【问题标题】:ImagePicker rotates iOS camera image 90 degreesImagePicker 将 iOS 相机图像旋转 90 度
【发布时间】:2013-06-24 18:37:45
【问题描述】:

我在我的应用程序中使用图像选择器。它适用于大多数图像,但是,它对最初从 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];
}
}

【问题讨论】:

  • 我不记得我使用的修复程序,但我记得有一个丢失方向保存 png 表示的问题。如果我发现我做错了什么,但请调查一下。
  • 啊,是的,保存为 png 是问题所在。改成 JPEG 就可以了!

标签: objective-c uiimagepickercontroller photos


【解决方案1】:

这个问题仍然显示为未回答,但问题已通过将 png 表示更改为 jpg 得到解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-20
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多