我正在尝试使用以下代码保存从UIImagePickerController获取的图像:
NSString *docsDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
objectAtIndex:0];
NSString *path = [docsDirectory stringByAppendingPathComponent:@"myImage.png"];
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[UIImagePNGRepresentation(image) writeToFile:path atomically:YES];
保存图像后,我再次在另一个屏幕上读取图像:
NSString *docsDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
objectAtIndex:0];
NSString *path = [docsDirectory stringByAppendingPathComponent:@"myImage.png"];
UIImage *extractedImage= [UIImage imageWithContentsOfFile:pngPath];
此代码在iPhone 4(iOS 5.1.1)上正常运行,但在iPhone 4(iOS 5.1.1),iPad 1(iOS5.1)和iPad 2(iOS5.1.1)设备上,此代码随机运行。 / p>
有时第一次保存图像,有时在尝试2-3次后保存图像。