When using the front camera of the iPhone 4 to take a picture, the taken picture is mirrored compared with what you see on the iPhone screen. How may I restore the "on screen" view of the UIImage (not the UIImageView), and be able to save it like this ?
I tried :
UIImage* transformedImage = [UIImage imageWithCGImage:pickedImage.CGImage scale:1.0 orientation:UIImageOrientationLeftMirrored];
UIImageWriteToSavedPhotosAlbum (transformedImage, self, @selector(photoSaved:didFinishSavingWithError:contextInfo:), nil);
then putting it on screen. It is nearly the same as seen on screen, but the saved image is distorted.
So... How may I restore the "on screen" view of the UIImage (not the UIImageView), and be able to save it like this ?
I also tried this way :
UIImage* pickedImage = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
UIImage* transformedImage;
CGSize imageSize = pickedImage.size;
UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1.0);
GContextRef ctx = UIGraphicsGetCurrentContext();
CGContextRotateCTM(ctx, 3.14); // rotate by 180°
CGContextScaleCTM(ctx, 1.0, -1.0); // flip vertical
CGContextDrawImage(ctx, CGRectMake(0.0, 0.0, imageSize.width, imageSize.height), pickedImage.CGImage);
transformedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
But that just gives a black image.
As the other answers, I had the same problem. But just flip the final image is only half the answer, because the preview image, displayed by the UIPickerController when you take a picture with the front camera, it's still inverted (mirrored).
Based in some codes from internet, I created a Pod to get this wanted behavior:
https://github.com/lucasecf/LEMirroredImagePicker
After installed, you just have to call this two lines of code together with your
UIImagePickerController
:And thats it, simply as that. You can check for more informations in the README of the github link.
Andrew Park's answer works great. This is Swift version.
You might want to mirror the image you get from the camera but what you originally get is correct. Take a picture with text to compare.
I'd like to vote up @Lucas Eduardo , I have tried to integrate the component LEImagePickerController into my project as below:
The best way is to draw the image into a new context.
This was written out of memory and without aid of a compiler, please don't copy and paste...