Kapil Choubisa
Kapil Choubisa

Reputation: 5232

Image get mirrored in UIImagePickerController with frontFacingCamera

I am working on an App and capturing images using UIImagePickerController. When application launches UIImagePickerController's object it has back camera as default selection. Everything works fine with back camera.

However, when I change the camera source to frontFacingCamera from imagePicker's toggle camera button and capture image, I get a mirrored image. My left arm shows as right arm in image. How do I solve this issue?

  1. So is it possible to resolve this issue with UIImagePickerController?
  2. If not that is there any way I can do image processing to get normal image?
  3. Is it mandatory to learn AVFoundation classes for this issue?
  4. if yes to 3rd. Please navigate me to a good tutorial for this.

Unfortunately, I am very weak in AVFoundation.

Upvotes: 0

Views: 1456

Answers (2)

TtheTank
TtheTank

Reputation: 332

Plz try below code

- (UIImage *)PictureFlipe:(UIImage *)picture
{
    UIImage * flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationLeftMirrored];

    return flippedImage;
}

Upvotes: 0

btype
btype

Reputation: 1576

I had the same problem and used this Method to mirror the image the other way round.

- (UIImage *) flipImageLeftRight:(UIImage *)originalImage {
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:originalImage];

    UIGraphicsBeginImageContext(tempImageView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

     //CGAffineTransformMake(<#CGFloat a#>, <#CGFloat b#>, <#CGFloat c#>, <#CGFloat d#>, <#CGFloat tx#>, <#CGFloat ty#>)
     CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0,  tempImageView.frame.size.height);
     CGContextConcatCTM(context, flipVertical);

     [tempImageView.layer renderInContext:context];

     UIImage *flipedImage = UIGraphicsGetImageFromCurrentImageContext();
     flipedImage = [UIImage imageWithCGImage:flipedImage.CGImage scale:1.0 orientation:UIImageOrientationDown];
     UIGraphicsEndImageContext();

     [tempImageView release];

     return flipedImage;
}

Upvotes: 1

Related Questions