修复图像+ iphone的方向

时间:2012-03-27 11:21:54

标签: iphone

我在应用程序中使用相机功能,并在单击照片后将图像保存在文档目录中。每当我使用图像时,这些图像的方向都会发生变化。因此,我搜索stackoverflow并在此链接中获取解决方案:

iOS UIImagePickerController result image orientation after upload

但我无法知道如何使用修复方向方法来获取图像的原始方向。如果有人对此有所了解,请帮助我。

感谢所有人。

2 个答案:

答案 0 :(得分:6)

在某处添加该方法。然后:

UIImage *origImage = <from somewhere>;
UIImage *fixed = [origImage  fixOrientation];

这是一种类别方法,因此您可以将其添加到任何实现中。通常,好的做法是创建一个单独的文件,比如说UIImage+rotationFix.{m,h}

答案 1 :(得分:3)

  1. 在项目中添加此类别

      

    的UIImage + fixOrientation

    或者您可以通过以下链接手动创建

    [1]:[UIImage + FixOrientation.h的代码]

    https://github.com/j3r3miah/mapmatic-ios/blob/master/Mapmatic/UIImage+FixOrientation.h

    [2]:[UIImage + FixOrientation.m的代码]

    https://github.com/j3r3miah/mapmatic-ios/blob/master/Mapmatic/UIImage+FixOrientation.m

    创建此类别后,在视图控制器中导入它

    import“UIImage + fixOrientation.h”

    并实现此UIImagePickerController委托

    - (void) imagePickerController: (UIImagePickerController *) picker
     didFinishPickingMediaWithInfo: (NSDictionary *) info {
    
            UIImage *myimage = [info objectForKey: UIImagePickerControllerOriginalImage];
            myimage=myimage.fixOrientation;
    }
    
    This fixOrientation method would fix the image orientation in portrait mode.