Rotate an iOSImage

Does anyone have some working code to rotate an iOSImage/UIImage? I’ve tried 7 different variations I found on SO and other sites but nothing seems to work and the new image I create is never rotated… Thanks in advance.

The easiest way I’ve found is to call Xojo’s iOSImage.ToData method which leaves out EXIF data resulting in an image rotated 180 degrees… :wink: But then you already knew that. :slight_smile:

Yeah I wish it were that simple. This is because of a similar situation. It seems that the still image capture classes in AVFoundation might not provide exif data. I’m still investigating it but right now the only way to have the images correctly oriented is if I rotate the returned image 90 degrees.

Is that 90 degrees in all cases? I find that if I take a landscape photo with my device rotated to the right (i.e. camera on the bottom) the native iOSImage.ToData returns an image rotated 180 degrees (i.e. upside down). So instead I use your declare (thanks again!) to avoid this issue and instead get one with EXIF data included so it can be shown with the correct rotation.

Yes the images are rotated 90 degrees counter clockwise no matter the orientation of my phone camera, so simply rotating them 90 degrees clockwise should fix it I think.

Ok so I figured out the underlying problem - the AVFoundation classes default setting is wrong and must be changed to the proper setting before a picture is taken. Unfortunately Apple doesn’t document that anywhere ;p. Changing the setting causes the class to return the correct exif data so the image is correctly oriented without modifications.

That said, if someone has code to rotate an iOSImage I would happily add it to iOSKit since I think people could definitely need it.

For OS X you need CIFilterAffineTransform

Fist you need to set the pivot point (translate) and then rotate (rotateByDegrees).
Should be the same for iOS I guess.