iphone image captured from camera rotate -90 degree automatically

后端 未结 7 1532
后悔当初
后悔当初 2020-12-01 04:57

Programatically I have fetched image from my camera in my app. It has been fetched nicely but when I shift to another view and dismiss that view at that time my image automa

7条回答
  •  無奈伤痛
    2020-12-01 05:31

    This method works for me,

    - (UIImage*) rotateImageAppropriately:(UIImage*)imageToRotate
    {
       UIImage* properlyRotatedImage;
    
       CGImageRef imageRef = [imageToRotate CGImage];
    
       if (imageToRotate.imageOrientation == 0)
       {
           properlyRotatedImage = imageToRotate;
       }
       else if (imageToRotate.imageOrientation == 3)
       {
    
           CGSize imgsize = imageToRotate.size;
           UIGraphicsBeginImageContext(imgsize);
           [imageToRotate drawInRect:CGRectMake(0.0, 0.0, imgsize.width, imgsize.height)];
           properlyRotatedImage = UIGraphicsGetImageFromCurrentImageContext();
           UIGraphicsEndImageContext();
       }
       else if (imageToRotate.imageOrientation == 1)
       {
           properlyRotatedImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:1];
       }
    
       return properlyRotatedImage;
    }
    

提交回复
热议问题