2012-12-13 2 views
1

iOS에서 프로토 타입 응용 프로그램을 제작하고 있으며 일부 Apple 샘플 코드를 해치 우고 있습니다 (얇은 얼음,이 코드는 goto 문을 사용합니다 : \). 세션 520의 AVCam 프로젝트 - 카메라 캡처의 새로운 기능을 사용하고 있습니다. 비디오 캡처 기능은 필요 없지만 여전히 사진 만 캡처 할 수 있습니다.iPad 캡처 16 : 9 사진

// Init the device inputs 
    AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil]; 
    AVCaptureDeviceInput *newAudioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self audioDevice] error:nil]; 


    // Setup the still image file output 
    AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 
    NSDictionary *outputSettings = @{AVVideoCodecKey: AVVideoCodecJPEG}; 
    [newStillImageOutput setOutputSettings:outputSettings]; 


    // Create session (use default AVCaptureSessionPresetHigh) 
    AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init]; 


    // Add inputs and output to the capture session 
    if ([newCaptureSession canAddInput:newVideoInput]) { 
     [newCaptureSession addInput:newVideoInput]; 
    } 
    if ([newCaptureSession canAddInput:newAudioInput]) { 
     [newCaptureSession addInput:newAudioInput]; 
    } 
    if ([newCaptureSession canAddOutput:newStillImageOutput]) { 
     [newCaptureSession addOutput:newStillImageOutput]; 
    } 

    [self setStillImageOutput:newStillImageOutput]; 
    [self setVideoInput:newVideoInput]; 
    [self setAudioInput:newAudioInput]; 
    [self setSession:newCaptureSession]; 

을 그리고 여기 셔터 버튼을 누를 때라고하는 방법입니다 :

장치의 입력과 출력은 thusly 히 설정되어

- (void) captureStillImage 
{ 
    AVCaptureConnection *stillImageConnection = [[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo]; 
    if ([stillImageConnection isVideoOrientationSupported]) 
     [stillImageConnection setVideoOrientation:orientation]; 

    [[self stillImageOutput] 
     captureStillImageAsynchronouslyFromConnection:stillImageConnection 
      completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 

       ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) { 
        if (error) 
        { 
         if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) 
         { 
          [[self delegate] captureManager:self didFailWithError:error]; 
         } 
        } 
       }; 

       if (imageDataSampleBuffer != NULL) 
       { 
        NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 

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

        if ([self.delegate respondsToSelector:@selector(captureManagerCapturedImage:)]) 
        { 
         dispatch_async(dispatch_get_main_queue(), ^{ 
          [self.delegate captureManagerCapturedImage:image]; 
         }); 
        } 

        [library writeImageToSavedPhotosAlbum:[image CGImage] 
               orientation:(ALAssetOrientation)[image imageOrientation] 
              completionBlock:completionBlock]; 

       } 
       else 
       { 
        completionBlock(nil, error); 
       } 

       if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) 
       { 
        [[self delegate] captureManagerStillImageCaptured:self]; 
       } 
      }]; 
} 

이 코드가 성공적으로 이미지를 캡처 및 저장 도서관에. 그러나 내가 작업하는 동안 어느 시점에서 5 메가 픽셀 4 : 3 이미지 캡처에서 1920x1080 16 : 9 이미지 캡처로 변경되었습니다. 종횡비가 지정되어있는 곳을 찾을 수 없으며 카메라 구성, 세션 캡처 또는 연결 캡처와 관련된 코드를 변경하지 않았습니다. 카메라가 16 : 9의 사진을 찍기 시작한 이유는 무엇입니까?

업데이트 : Apple의 원본 샘플 코드를 다시 실행했으며 비디오에서 직접 캡처 한 16 : 9 이미지를 저장하는 것으로 보입니다. 전에는 미쳐 있었거나 Camera.app로 테스트 샷을 찍었습니다. 그래서 진짜 질문은, 내가 촬영하는 동안 카메라에서 라이브 피드를 화면에 표시하고 전체 해상도의 사진을 찍는 방법입니다. 라이브 카메라 피드 위에 물건을 오버레이 할 수 있어야하므로 UIImagePickerController을 사용할 수 없습니다.

업데이트 2 : 내가 사용하고있는 AVCapture 코드를 버리면 해결할 수있었습니다. UIImagePickerController가 필요한 것을 수행한다는 것이 밝혀졌습니다. 사용자 정의 컨트롤을 오버레이 할 수 있다는 것을 알지 못했습니다. 사진을 찍을 때까지 전체 화면을 차지한다고 생각했습니다.

+0

카메라에서 프레임을 캡처합니까? 왜냐하면 16 : 9로 끝나는 것을 의미하기 때문입니다. 프레임을 캡처하고 사진을 찍는 것은 다른 일입니다. – Oritm

+0

아, 그게 문제 일 수 있습니다. 비디오의 프레임뿐만 아니라 전체 해상도의 사진을 캡처하고 싶습니다. 기묘한 것은, 내가 말할 수있는 한, 어제, 그것이 자연스럽게 바뀌는 것처럼 보였던 어제까지, 전체 크기의 사진을 캡쳐하고 있었다. –

+0

이 방법으로 문제가 해결되면 답장에 의견을 복사 해 드리겠습니다. 그렇지 않은 경우 코드를 깊이 들어가야합니다. – Oritm

답변

1

비디오 소스에서 프레임을 캡처하는 경우 16시 9 분의 해상도로 끝납니다. 비디오 소스에서 프레임을 캡처하고 사진을 찍는 것은 다른 일입니다.

+1

카메라에서 라이브 피드를 표시하고 전체 해상도 스틸을 캡처하는 방법은 무엇입니까? '- [UIImagePickerController cameraOverlayView]'가 내가 필요한 것 (오버레이를 표시하는 데 필요한 것)에 가깝지만, 각각 간의 UI 상호 작용을 위해 일시 ​​중지하지 않고 사진을 찍을 수 있어야합니다. –

+0

실제로 나는'UIImagePickerController'와 함께 동작시킬 수있을 것이라고 생각합니다. 어느 쪽이든, 당신의 대답은 정확합니다 - 나는 정식 스틸을 캡쳐해야했을 때 라이브 비디오 프레임을 캡쳐했습니다. –

+0

확실하지 않습니다 .. 내일 이것을 확인해 드리겠습니다. – Oritm

관련 문제