iphone image captured from camera rotate -90 degree automatically

后端 未结 7 1537
后悔当初
后悔当初 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: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];
    }
    

提交回复
热议问题