UIImageWriteToSavedPhotosAlbum Problem
i try to save a photo from camera after take a photo with a button .
here is my codes:
-(IBAction)savePhoto{
UIImageWriteToSavedPhotosAlbum(开发者_如何学Cimg.image, 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];
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
but i dont know why doesnt save anything !
I suspect your image is released before you save it:
img.image = [info objectForKey:UIImagePickerControllerOriginalImage];
The line above returns an autoreleased object. I suggest you retain the image as shown below and then release it when you have saved the image.
img.image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
Call [self savePhoto]
in -imagePickerController:didFinishPickingMediaWithInfo:
after retrieving the image.
精彩评论