Save image to camera roll with UIImageWriteToSavedPhotosAlbum

谁都会走 提交于 2019-12-30 02:29:09

问题


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 ?


回答1:


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);
}


来源:https://stackoverflow.com/questions/2538907/save-image-to-camera-roll-with-uiimagewritetosavedphotosalbum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!