Image gets rotated when retrieved from file

rattletrap99

I'm modifying some code from an online lesson on using UIPickerViewController.

I'm taking a photo, displaying in a UIImageView in my first View Controller, then saving it to file. Then I retrieve it and display it in a UIImageView in my second View Controller. The UIImageViews are the same size (375 x 315), and use the same settings:

enter image description here

The first VC looks like this after snapping the picture and hitting the "Use photo" button on the UIPickerViewController interface:

enter image description here

The second VC looks like this after I retrieve the pic (I'm using PNG):

enter image description here

I've banged around a lot on SO, yet haven't found a solution for iOS. Can someone please point me in the right direction? I can supply any code (which seems unremarkable), but I don't think that's where the problem lies.

Thanks! All Help appreciated!

rattletrap99

I got my answer right here, which was only a click or two away from the link provided by @ocanal in his comment above. I did have to convert from Obj C to Swift, but it works like magic. Here's the code I added to achieve the correct orientation:

let originalImage = UIImage(contentsOfFile: imagePath)

var imageToDisplay: UIImage? = nil
if let anImage = originalImage?.cgImage {
    imageToDisplay = UIImage(cgImage: anImage, scale: originalImage!.scale, orientation: .right)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android getting an image from gallery comes rotated

CSS to auto-fit image to screen when iPhone rotated from portrait to landscape

Rotated Image gets distorted and blurry?

Image rotated 90 degrees when taken a selfie

Camera image gets rotated when I upload to server

Prevent alt text of an img tag from being rotated when the image is not found

When i take a photo,It gets rotated 90 degrees anti clockwise

urllib.request.urlretrieve got stuck when retrieved just one image from a site

the view size gets smaller when the view is rotated

Displaying image retrieved from google drive

How gets size of char[] when i read from a text file

boundaries cut the image when rotated

How can I access JSON data when its retrieved from an external file?

Image not being retrieved from Dropbox

full screen image on webpage is squashed when device is rotated only from portrait to landscape

How to make an image retrieved from a database responsive?

Image rotated when chosen from gallery

Image captured from custom camera gets rotated after cropping iOS

While using UIImagePickerController in Xamarin.iOS, when I select any front cam image, it gets rotated 90 degrees counter clockwise

Image gets mangled when saving InkCanvas to byte array to file

How do you assign an image to a student record when the record is retrieved from the database?

display an image retrieved from its URI

How to mask a rotated rectangle from an image?

Image Gets rotated captured from camera

Image gets Rotated when using with img tag in React; Looks fine when opened with windows viewer

Is it possible to remove black borders from rotated image?

Java rotated buffered image gets cut off

Check whether the file retrieved from Firestore is empty

Data from Sybase image column truncated at 32 KiB when retrieved via pyodbc