-1

I am facing some issues with the orientation of the photos. After taking a portrait picture and saving it to the camera roll, I see it rotated. But when I add it to an Image View it looks ok. Anyone else found the same issue? Is there an open bug in the Feedback Assistant? Thanks!

Same issue happened when I tried to save it using the PHPhotoLibrary

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //Saves rotated
    imageView.image = image; //Appears OK
    [self dismissModalViewControllerAnimated:YES];
}
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
assetPlaceholder = changeRequest.placeholderForCreatedAsset;
Hasya
  • 9,792
  • 4
  • 31
  • 46

1 Answers1

-1

I have this extension in my project. Try it.

extension UIImage {
    func fixOrientation() -> UIImage {
        if imageOrientation == .up {
            return self
        }
        UIGraphicsBeginImageContextWithOptions(size, false, scale)
        draw(in: CGRect(origin: .zero, size: size))
        let normalizedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() ?? self
        UIGraphicsEndImageContext()
        return normalizedImage
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Alexandr Kolesnik
  • 1,929
  • 1
  • 17
  • 30
  • 1
    1. The question is tagged Objective-C, not Swift. Please post answers in the proper language. 2. Please don't post code-only answers. A good answer explains what was wrong in the question and it explains how the answer solves the problem. – rmaddy Jul 30 '19 at 16:06