I am developing the front facing camera app in iPad2 by using the UIImagePickerController
.
When I capture the image it's shows as flipped from left to right.
How do I correct this?
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imgPkr = [[UIImagePickerController alloc] init];
imgPkr.delegate = self;
imgPkr.sourceType = UIImagePickerControllerSourceTypeCamera;
imgPkr.cameraDevice=UIImagePickerControllerCameraDeviceFront;
UIImageView *anImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"select%d.png",val]]];
anImageView.frame = CGRectMake(0, 0, anImageView.image.size.width, anImageView.image.size.height);
imgPkr.cameraOverlayView = anImageView;
[theApp.TabViewControllerObject presentModalViewController:imgPkr animated:YES];
[imgPkr release];
}
You can flip the image from the source image use this
Edit: Added swift code
Full Working Example in Swift, which answers to the initial question of this post (tested on an iPhone 5c using iOS 8.2):
I know this question is really old but it seems like this is a still a common problem. Just set a
CGAffineTransform
on thecameraViewTransform
property on aUIImagePickerController
object.Updated "bandog" answer for swift 4
Just to add how I have just achieved this without subclassing UIImagePickerController and without adding extra buttons to the camera view.
Simply listen for this notification which is fired several times whenever the camera is changed:
Then use this method to flip the camera view:
As the other answers, I had the same problem. As Yonatan Betzer mentioned, 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).
Yonatan Betzer's anwser works great, but he did not mentioned how or where to put the action to change the camera device.
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.