In my app I'm capturing images using the Camera. These are being stored in an NSArray as an NSData representation. When I convert the NSData back to the image, the orientation is now landscape instead of portrait as I took it.
NSData *data = UIImagePNGRepresentation([arrayImage objectAtIndex:0]);
UIImage *tmp = [UIImage imageWithData:data];
Anyone have an explanation? Thanks.
https://developer.apple.com/library/content/samplecode/AVCam/Introduction/Intro.html
I think this is a bug with the SDK. I ran into this exact problem and then switched over to UIImageJPEGRepresentation which fixed the problem.
you should fix orientation of image captured by camera the code follows, by default the orientation of camera image is not correct
-[UIImage imageOrientation] might help :)
Since that property is readonly, and depending on what you want to do, a possible (but ugly) solution could be:
(untested and there might/must be something cleaner)
EDIT : First part was an answer to your question, an explanation more than a fix.
This and this (old?) blog posts might be interesting readings for you. Strangely I've never met this issue while I'm using
UIImageJPEGRepresentation
to send images to a server... What iOS version are you working on? That could be an old SDK bug?Here is a slightly modified Xamarin.iOS (C#) version of the top answer, so that you don't have to rewrite it by hand as well ;-) .