2014-09-05 118 views
2

我使用苹果公司制造的AVCam作为我的自定义相机视图。老实说,如果你第一次看到它,那么就不要简单地理解课程AVCamViewController中发生了什么。AVCam保存全屏捕获的图像

现在我很感兴趣,他们如何设置捕获图像的帧。我试图找到一些名人或类似的东西,但我还没有找到任何东西。

我在谷歌搜索,发现这里的答案AVCam not in fullscreen

但是,当我实施了解决方案,我才意识到,这只是做直播摄像头预览层具有相同的大小作为我的观点,但是当应用程序的方法保存图像图片中的- (IBAction)snapStillImage:(id)sender图片仍然是左右两条条纹。

我的问题是如何删除此条纹或在源代码中的哪一行苹果设置这个东西?

此外,作为附加的子问题,我如何设置类型创建照片,因为应用程序要求我“麦克风设置”,我不需要它只是需要照片,就是这样。

来自苹果的这段代码将图片保存到照片库。

- (IBAction)snapStillImage:(id)sender 
{ 
    dispatch_async([self sessionQueue], ^{ 
     // Update the orientation on the still image output video connection before capturing. 
     [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]]; 

     // Flash set to Auto for Still Capture 
     [AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]]; 

     // Capture a still image. 
     [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 

      if (imageDataSampleBuffer) 
      { 
       NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 

       UIImage *image = [[UIImage alloc] initWithData:imageData]; 

       UIImage *proccessingImage = [SAPAdjustImageHelper adjustImage:image]; 

       NSNumber *email_id = [SAPCoreDataEmailHelper currentEmailId]; 

       [SAPFileManagerHelper addImage:proccessingImage toFolderWithEmailId:email_id]; 
      } 
     }]; 
    }); 
} 
+0

请,根据添加代码或截图预览... – hmdeep 2014-09-05 11:49:30

+0

我的经验,它的做工精细的iPhone5的,但问题是,只在iPhone 4,右??? – hmdeep 2014-09-05 11:56:14

+0

您可以在此处下载代码https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html,如上所述。我没有修改任何 – 2014-09-05 11:57:26

回答

5

您是否在设置会话预设?

您可以使用会话预设中设置的会话AVCaptureSessionPresetPhoto

对于另一个子问题:您只需要添加AVCaptureStillImageOutput输出。

如何设置会话预设?

[session setSessionPreset:AVCaptureSessionPresetPhoto]; 

如何配置会话只使用StillImageOutput拍照和?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Create the AVCaptureSession 
    AVCaptureSession *session = [[AVCaptureSession alloc] init]; 
    [self setSession:session]; 

    // Setup the preview view 
    [[self previewView] setSession:session]; 

    // Setup the session Preset   
    [session setSessionPreset:AVCaptureSessionPresetPhoto]; 

    // Check for device authorization 
    [self checkDeviceAuthorizationStatus]; 

    dispatch_queue_t sessionQueue = dispatch_queue_create("session queue", DISPATCH_QUEUE_SERIAL); 
    [self setSessionQueue:sessionQueue]; 

    dispatch_async(sessionQueue, ^{ 
     //[self setBackgroundRecordingID:UIBackgroundTaskInvalid]; 

     NSError *error = nil; 

     AVCaptureDevice *videoDevice = [AVCamViewController deviceWithMediaType:AVMediaTypeVideo preferringPosition:AVCaptureDevicePositionBack]; 
     AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; 

     if (error) 
     { 
      NSLog(@"%@", error); 
     } 

     if ([session canAddInput:videoDeviceInput]) 
     { 
      [session addInput:videoDeviceInput]; 
      [self setVideoDeviceInput:videoDeviceInput]; 

      dispatch_async(dispatch_get_main_queue(), ^{ 
       // Why are we dispatching this to the main queue? 
       // Because AVCaptureVideoPreviewLayer is the backing layer for AVCamPreviewView and UIView can only be manipulated on main thread. 
       // Note: As an exception to the above rule, it is not necessary to serialize video orientation changes on the AVCaptureVideoPreviewLayer’s connection with other session manipulation. 

       [[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)[self interfaceOrientation]]; 
      }); 
     } 

AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 
     if ([session canAddOutput:stillImageOutput]) 
     { 
      [stillImageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}]; 
      [session addOutput:stillImageOutput]; 
      [self setStillImageOutput:stillImageOutput]; 
     } 
    }); 
} 
+0

好的我今天会检查您的答案,非常感谢)我会将它标记为已接受的问题,我测试它) – 2014-09-08 20:24:45

+0

由于某种原因,应用程序崩溃后,我采取2或一张照片 – 2014-09-08 21:39:43

+0

所以我刚刚添加了一行[会话setSessionPreset:AVCaptureSessionPresetPhoto];它工作完美,但当应用程序开始调用snapStillImage应用程序崩溃。删除这行应用程序需要照片,但有黑色条纹 – 2014-09-08 21:50:17

0

需要的字段,以保持纵横比,如果想避开他们,你应该改变videoGravityAVCaptureVideoPreviewLayer,或在UIImageViewcontentMode显示所拍摄图像的黑人。
这是一个预期的行为,不理解你的关注。

+0

当我使用UIIMagePickerController时,我确实很棒!图像没有任何条纹。但是当运行苹果源时,我得到了一半的图像,而不是100的大小,这是一个问题,视频重力是可以的,但只能用于预览,任何情况下,图库中保存的图像将具有iPad屏幕的一半大小, t使用任何UIImageView – 2014-09-05 12:55:15

+0

我已经添加了代码,苹果用于保存图像到图书馆,是否有苹果提供的AVCam示例中的任何UIImageView?关于您说的contentMode? – 2014-09-05 12:57:27

+0

我也发现这个链接http://stackoverflow.com/questions/20497575/avcam-not-in-fullscreen,但正如我所说,它只是让全屏幕的现场录音组件。使用这种方法将图像保存到库后 - (IBAction)snapStillImage:(id)sender图像将具有iPad屏幕大小的一半大小。 – 2014-09-05 12:59:19