图像选择器有两种成功委托方法,如下所示:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo;
// This is Deprecated in ios 3.0
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
在我看来,您使用的是第一种方法(您没有提到该方法,但我想让您知道)。在这种情况下,您必须将实现更改为第二种方法。
要访问 UIImage 并将其存储到某个路径,请使用如下:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//Zoomed or scrolled image if picker.editing = YES;
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
// Original Image
UIImage *OriginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// You can directly use this image but in case you want to store it some where
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docDirPath stringByAppendingPathComponent:@"myImage.png"];
NSLog (@"File Path = %@", filePath);
// Get PNG data from following method
NSData *myData = UIImagePNGRepresentation(editedImage);
// It is better to get JPEG data because jpeg data will store the location and other related information of image.
[myData writeToFile:filePath atomically:YES];
// Now you can use filePath as path of your image. For retrieving the image back from the path
UIImage *imageFromFile = [UIImage imageWithContentsOfFile:filePath];
}
希望这可以帮助你:)