开发者

Save image to camera roll with UIImageWriteToSavedPhotosAlbum

I am trying to save a photo with a button to camera roll after user capture a picture with Camera , but I don't know why my picture doesn't save at photo library !!

Here is my code :

开发者_开发问答
-(IBAction)savePhoto{

    UIImageWriteToSavedPhotosAlbum(img.image,nil, nil, nil);

}

-(IBAction)takePic {

    ipc = [[UIImagePickerController alloc]init];
    ipc.delegate = self;
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentModalViewController:ipc animated:YES];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    img.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];   
}

Variable name ipc is UIImagePickerController and img is UIIMageView.

what's my problem ?


First make sure you are calling savePhoto. Then you can add an assertion to check that the image is not nil:

- (IBAction) savePhoto {
    NSParameterAssert(img.image);
    UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜