【问题标题】:UIImagePickerController front camera show mirror image on preview viewUIImagePickerController 前置摄像头在预览视图上显示镜像
【发布时间】:2015-06-04 12:53:48
【问题描述】:

我知道很多人都问过这个问题,但我没有找到解决这个问题的正确答案,我的问题是:如何在预览视图中制作照片(用户点击捕获按钮后,以及然后转到预览视图让用户预览)不镜像,可以在 UIImagePickerController 中修复此问题,我知道如何旋转照片,UIImageOrientation 中的枚举中的东西UIImageOrientationUp ,我知道这是什么意思是。

尝试1:

我在用户点击 capture 按钮后去预览视图并使用我有镜像的照片覆盖默认照片(使用cameraOverlayView)后获取照片,我可以检测到用户点击 capture 按钮使用 NSNotificationCenter@"_UIImagePickerControllerUserDidCaptureItem",但我找不到获取照片的方法。

尝试2:

我使用cameraViewTransform,但是当用户在底部或顶部的Home按钮拍照(前置摄像头)时,预览视图上的图像不是镜像,而是当Home左侧或右侧的按钮,在用户点击捕获之前手机上的图像有一些问题,虽然预览视图上的图像不是镜像。使用AVCaptureDeviceDidStartRunningNotification通知。

- (void)cameraChanged:(NSNotification *)notification
{
  if(self.imagePickerController.cameraDevice == UIImagePickerControllerCameraDeviceFront)
  {
     self.imagePickerController.cameraViewTransform = CGAffineTransformIdentity;
     self.imagePickerController.cameraViewTransform = CGAffineTransformScale(self.imagePickerController.cameraViewTransform, -1, 1);
     if (self.imagePickerController.cameraOverlayView) {
        NSLog_DEBUG(@"self.imagePickerController.cameraOverlayView is not nil");
    } else {
        NSLog_DEBUG(@"self.imagePickerController.cameraOverlayView is nil");
    }
    self.imagePickerController.cameraOverlayView.transform = CGAffineTransformScale(self.imagePickerController.cameraViewTransform, -1, 1);
  } else {
    self.imagePickerController.cameraViewTransform = CGAffineTransformIdentity;
  }
}

【问题讨论】:

    标签: ios objective-c uiimagepickercontroller


    【解决方案1】:

    最后,我无法在UIImagePickerController 中解决这个问题,但我使用AVFoundationCoreMotion 解决了这个问题,你可以看到AVCam

    //init the motionManager
    - (void)initializeMotionManager{
      motionManager = [[CMMotionManager alloc] init];
      motionManager.accelerometerUpdateInterval = .1;
      motionManager.gyroUpdateInterval = .1;
    
      [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
                                        withHandler:^(CMAccelerometerData  *accelerometerData, NSError *error) {
                                            if (!error) {
                                                [self outputAccelertionData:accelerometerData.acceleration];
                                            }
                                            else{
                                                NSLog_DEBUG(@"%@", error);
                                            }
                                        }];
      }
    
    //detect the device orientation
    - (void)outputAccelertionData:(CMAcceleration)acceleration{
    
      if (acceleration.x >= 0.75) {
          _orientationNew = UIInterfaceOrientationLandscapeLeft;
      }
      else if (acceleration.x <= -0.75) {
          _orientationNew = UIInterfaceOrientationLandscapeRight;
      }
      else if (acceleration.y <= -0.75) {
          _orientationNew = UIInterfaceOrientationPortrait;
      }
      else if (acceleration.y >= 0.75) {
          _orientationNew = UIInterfaceOrientationPortraitUpsideDown;
      }
      else {
          // Consider same as last time
          return;
      }
    
      if (_orientationNew == _orientationLast)
          return;
    
      _orientationLast = _orientationNew;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      相关资源
      最近更新 更多