When I take picture in Portrait Mode, savedImage
is automatically rotated when setting to UIImageView
.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"ProfilePicture.png"];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
UIImage *savedImage = [UIImage imageWithData:[NSData dataWithContentsOfFile:filePath]];
But when I use UIImageJPEGRepresentation: writeToFile: atomically:
method, the result Image has No Issues.
Can anyone please explain why I didn't get image in correct orientation while using UIImageJPEGRepresentation
& not in UIImagePNGRepresentation
.
NB: I tried
UIImage *imageToDisplay =
[UIImage imageWithCGImage:[originalImage CGImage]
scale:[originalImage scale]
orientation: UIImageOrientationUp];
to save imageToDisplay
, but not working