【问题标题】:NSData from UIImage. Uploading to server with wrong orientation来自 UIImage 的 NSData。以错误的方向上传到服务器
【发布时间】:2014-03-20 09:25:03
【问题描述】:

我正在尝试使用UIImageJPEGRepresentation 上传取自UIImagePickerControllerUIImage。但它显示在错误方向的服务器上。首先,我想问一下有没有办法在我这边解决它?或者如果不是如何在服务器上处理它?

我已经看到iOS 4 Image Oriented Incorrectly When Posted To Server 和这个Save UIImage, Load it in Wrong Orientation 但我需要直接在服务器上而不是在应用程序中显示正确方向的图像。

【问题讨论】:

  • 看看stackoverflow.com/questions/5427656/… 它可能会帮助您修复图像方向。
  • @VincentZgueb 如果我想在 imageView 中显示图像但是当我将其转换为 NSData 并发送到服务器时方向会发生变化,它会有所帮助。在我们从选择器方向选择图像的那一刻是正确的。
  • 我也有同样的问题……你找到解决方案了吗?

标签: ios objective-c uiimage nsdata


【解决方案1】:

根据我的发现,这似乎是最好的答案。 iOS UIImagePickerController result image orientation after upload

在您的项目中添加类别 UIImage+fixOrientation 并在您的视图控制器中导入“UIImage+fixOrientation.h”。

那么你应该可以使用这样的东西了。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
    image = [image fixOrientation];

    NSData *data = UIImageJPEGRepresentation(image, 1.0);

}

【讨论】:

  • 否 :( 因为当我们将 UIImage 转换为 NSData 时,方向会发生变化,而不是在我们选择它时。
  • 你有没有专门试过这个?方向更改不是由将其转换为 NSData 引起的。从图像选择器返回的原始图像仅具有存储为 exif 数据的方向,此代码会旋转图像本身。
【解决方案2】:

试试

UIImage *orientationFixedImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:1.0 orientation:originalImage.imageOrientation];

【讨论】:

    猜你喜欢
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多