iphone image captured from camera rotate -90 degree automatically

后端 未结 7 1530
后悔当初
后悔当初 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:15

    If you are still need some solution just refer this link where I posted my answer for this problem just refer edit and edit 1 also see the last 2 or 3 comments for further reference

    0 讨论(0)
  • 2020-12-01 05:19

    Try this property

    @property (nonatomic) CGAffineTransform cameraViewTransform

    and rotate is with -90 degree and then capture the image. If doesn't work the use the code given by Cocoa Matters.

    0 讨论(0)
  • 2020-12-01 05:23

    The bad behavior has now changed with 13.4. Images are now captured with accurate orientation.

    0 讨论(0)
  • 2020-12-01 05:30

    The most simplest way to overcome this problem is by scaling the image inside didFinishPickingImage delegate. You can use the following code to scale by importing a class "UIImage+ImageScaling.h".

    theImage =[UIImage imageWithImage:image scaledToSizeWithSameAspectRatio:CGSizeMake(400, 300)]; // for iphone.

    0 讨论(0)
  • 2020-12-01 05:30

    It is due to your image orientation. so keep original image orientation. you will get the image orientation in your UIImagePickerController delegate method

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    

    sample code:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    
        UIImage *sourceImage = [info valueForKey:UIImagePickerControllerOriginalImage];
    
        NSData *data = UIImagePNGRepresentation(sourceImage);
        UIImage *tmp = [UIImage imageWithData:data];
        UIImage *afterFixingOrientation = [UIImage imageWithCGImage:tmp.CGImage
                                             scale:sourceImage.scale
                                       orientation:sourceImage.imageOrientation];
    
        [self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
    }
    
    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题