我在我的应用程序中使用图像选择器。它适用于大多数图像,但是,它对最初从 iPhone 4 相机拍摄的图像有问题(我认为因为它们太大了)。iPhone 5 相机的照片和屏幕截图都可以正常工作。上传最初从 iPhone 4 相机拍摄的照片时,选择器会将它们向左旋转 90 度。我认为这也是相关的,但我的应用程序有一个功能,用户可以将图像保存到他们的相机胶卷,它适用于大多数图像,但从 iPhone 4 相机拍摄的旋转 90 度的图像不保存。
这是我的代码:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([self.imagePicker isEqual:picker])
{
//
// Saving into Documents folder
//
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/one.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok) {
NSLog(@"Error creating file %@", path);
} else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(info [UIImagePickerControllerOriginalImage])];
[myFileHandle closeFile];
}
//
// Loading from documents
//
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
self.chosenImageOne = loadedImage;
[self.imageViewOne setImage:self.chosenImageOne];
[self dismissViewControllerAnimated:YES completion:nil];
}
}