2014-11-25 57 views
0

我正在使用Apple的AVCam source code來創建自定義相機,其工作方式類似於魅力,問題是一旦我用它拍攝了視頻或圖像,然後將其檢入照片庫的方向改變爲風景(即使我以縱向拍攝它)。我爲此搜尋了很多,但無法找到一個方法。任何幫助?將視頻或圖像的方向改爲AVCam的人像

對於筆記,我的應用程序只支持肖像和只應在肖像捕捉。

更新:

AVCaptureConnection *captureConnection = ... 
if ([captureConnection isVideoOrientationSupported]) 
{ 
    AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationPortrait; 
    [captureConnection setVideoOrientation:orientation]; 
} 

這是行不通的。

回答

0

對於捕獲圖像,您應該設置方向。當您將圖像保存到磁盤時,您應該使用

writeImageToSavedPhotosAlbum:orientation:completionBlock: 

函數並設置了正確的「方向」參數。

用法:https://developer.apple.com/library/ios/documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/index.html#//apple_ref/occ/instm/ALAssetsLibrary/writeImageToSavedPhotosAlbum:orientation:completionBlock

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

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

     if (imageDataSampleBuffer) { 
      self.imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 

      [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:image.CGImage 
                  orientation:(ALAssetOrientation)[image imageOrientation] 
                 completionBlock:^(NSURL *assetURL, NSError *error) { 
                  if(error == nil) { 
                   NSLog(@"PHOTO SAVED - assetURL: %@", assetURL); 
                  } else { 
                   NSLog(@"ERROR : %@",error); 
                  } 
                 }]; 

上目標C實施例