相机图像正在iphone中自动更改方向

ish*_*hhh 1 iphone objective-c

我开发了一个照片应用程序

在这里,我使用来自照片库的图像以及通过相机拍摄并在图像视图中显示的图像.

来自照片库的图像的方向正确,但相机图像以不同的方向显示.

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"MyFolder"];
    NSString *imagePath = [dataPath stringByAppendingPathComponent:@"girl.jpg"];

    if ([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
        UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithContentsOfFile:imagePath].CGImage scale:bieberImage.image.scale
                                       orientation:NO]; 

     //   bieberImage.transform = CGAffineTransformMakeRotation(1.57079633);


    CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
    crossFade.duration = 3.0;


        crossFade.fromValue = (id)bieberImage.image.CGImage;

        crossFade.toValue = (id)image.CGImage;



        [self.bieberImage.layer addAnimation:crossFade forKey:@"animateContents"];

        }
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我如何纠正这个问题.

提前致谢.

Ray*_*eck 16

更换:

        UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithContentsOfFile:imagePath].CGImage scale:bieberImage.image.scale
                                   orientation:NO]; 
Run Code Online (Sandbox Code Playgroud)

附:

        UIImage *image = [UIImage imageWithCGImage:[UIImage imageWithContentsOfFile:imagePath].CGImage scale:bieberImage.image.scale
                                   orientation:UIImageOrientationRight]; 
Run Code Online (Sandbox Code Playgroud)

编辑:或试试这个:

 - (UIImage*) rotateImage:(UIImage* )src {

    UIImageOrientation orientation = src.imageOrientation;

    UIGraphicsBeginImageContext(src.size);

    [src drawAtPoint:CGPointMake(0, 0)];
    CGContextRef context = UIGraphicsGetCurrentContext();

     if (orientation == UIImageOrientationRight) {
         CGContextRotateCTM (context, [self radians:90]);
     } else if (orientation == UIImageOrientationLeft) {
         CGContextRotateCTM (context, [self radians:90]);
     } else if (orientation == UIImageOrientationDown) {
         // NOTHING
     } else if (orientation == UIImageOrientationUp) {
         CGContextRotateCTM (context, [self radians:0]);
     }

      return UIGraphicsGetImageFromCurrentImageContext();
 }

 - (CGFloat) radians:(int)degrees {
    return (degrees/180)*(22/7);
  }
Run Code Online (Sandbox Code Playgroud)