UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 65 - filtered version of loadImage() method yields rotated images

Forums > 100 Days of SwiftUI

This is a weird quirk I noticed when working through the Day 65 lesson, Basic image filtering using Core Image.

I'm testing this application on my device (iPhone 13 mini), rather than using the Simulator.

If I pass the image from the ImagePicker straight into a SwiftUI image view, the images are rotated as they appear in the photo library:

func loadImage() {
  guard let inputImage = inputImage else { return }
  image = Image(uiImage: inputImage)
}  

However, when I pass the image from the ImagePicker into the CoreImage filter, the images are rotated...randomly? Some are sideways, some are upside down, some are right-side up. If there's a pattern, I didn't notice:

func loadImage() { 
   guard let inputImage = inputImage else {
            return
        }

   let beginImage = CIImage(image: inputImage)
   currentFilter.setValue(beginImage, forKey: kCIInputImageKey)
   applyProcessing()
}

This doesn't happen to the images in the Simulator, but even there there's a quirk -- I cannot select the first image (the pink, purple and yellow flowers). If I click on that one, it just maintains the previously loaded image (if any).

Does anyone know why this might be happening, and if there's a workaround that forces the images back to their original rotation?

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.