iphone - 图像通过 frontFacingCamera 镜像到 UIImagePickerController 中

标签 iphone ios uiimage uiimagepickercontroller

我正在开发一个应用程序并使用UIImagePickerController捕获图像。当应用程序启动 UIImagePickerController 的对象时,它会将后置摄像头作为默认选择。后置摄像头一切正常。

但是,当我从 imagePicker 的切换相机按钮将相机源更改为 frontFacingCamera 并捕获图像时,我得到了镜像图像。我的左臂在图像中显示为右臂。我该如何解决这个问题?

  1. 那么可以使用 UIImagePickerController 解决这个问题吗?
  2. 如果不是,有什么方法可以进行图像处理以获得正常图像?
  3. 是否必须学习 AVFoundation 类才能解决此问题?
  4. 如果是,则第三个。请引导我找到一个很好的教程。

不幸的是,我在AVFoundation方面非常薄弱。

最佳答案

我遇到了同样的问题,并使用此方法以相反的方式镜像图像。

- (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;
}

关于iphone - 图像通过 frontFacingCamera 镜像到 UIImagePickerController 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949612/

相关文章:

iOS,如何绘制文字的动态长度?

iphone - 如何减慢UIPanGestureRecognizer的速度?

ios - HTML 字符串中无法识别项目符号点

ios - 无法更改 UITableViewController 颜色背景

ios - 为应用添加第三方SDK

ios - SKStoreProductViewController 因名为 sceneDisconnected : in iOS 15. 6 beta5 的无法识别选择器而崩溃

objective-c - 如何对图像中的颜色进行采样

swift - 为什么从 url 下载图像返回 nil?

iPhone:我可以将类方法用于 UIBarButtonItem 的 Action 选择器吗?

iphone - 如何将标题标签的大小设置为导航栏的全宽