2011-08-10 5 views
2

AVCaptureStillImageOutput에서 픽셀 데이터를 캡처하려고하는데 이미지를 CGImage로 자르면 다시 방향이 지정됩니다. 이를 테스트하기 위해 사진 라이브러리에 임시 이미지를 출력합니다. 이제는 이미지가 잘려지기 전에 전체 이미지가 아닌 동안 축소판이 회전된다는 사실을 알았습니다. 이 문제는 나중에 이미지의 적절한 크기가 필요한 사용자 정의 pixelDataManager에 UIImage를 전달할 때 문제가됩니다.AVCaptureStillImageOutput에서 UIImage 방향이 올바르지 않습니다.

설정 captureVideoPreviewLayer.orientation = AVCaptureVideoOrientationPortrait;[videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];은 변경되지 않았습니다.

모든 의견 ???

// Create a capture session 
    AVCaptureSession *session = [[AVCaptureSession alloc] init]; 
    session.sessionPreset = AVCaptureSessionPresetMedium; 

    AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; 

    // Add capture layer to visible view  
    captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResize; 
    captureVideoPreviewLayer.frame = screenBounds; 
    captureVideoPreviewLayer.bounds = screenBounds; 
    captureVideoPreviewLayer.orientation = AVCaptureVideoOrientationPortrait; 
    [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer]; 

    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

    // Setup error handling 
    NSError *error = nil; 
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; 
    if (!input) { 
     // Handle the error appropriately. 
     NSLog(@"ERROR: trying to open camera: %@", error); 
    } 
    [session addInput:input]; 

    // Start session 
    [session startRunning]; 

    // Output image data 
    stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil]; 
    [stillImageOutput setOutputSettings:outputSettings]; 

    [session addOutput:stillImageOutput]; 

2) 비디오 연결 설정 :

을 나는

1) 세션, 입력 및 출력을 설정 ... 섹션으로 그것을 깰 수있을

AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in stillImageOutput.connections) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo]) { videoConnection = connection; break; } } if (videoConnection) { break; } } if ([videoConnection isVideoOrientationSupported]) { [videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait]; } 

3) 출력 캡쳐 이미지 :

,536,
NSLog(@"about to request a capture from: %@", stillImageOutput); 
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
{   
    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; 
    UIImage *image = [[UIImage alloc] initWithData:imageData]; 
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); 
    //...... 
} 
+0

내가 [이미지 imageOrientation]보고가에 넣어 어떤 방향으로보고하려고합니다.이 잘못 설정되어 있다면, 먼저 이미지를 회전 한 다음 사진 앨범에 기록 할 수 있습니다. 희망이 도움이됩니다! – msgambel

+0

감사합니다. 나는 오늘 밤 그 모습을 보여 주겠다. 실제로 사진 앨범 출력이 필요하지 않습니다. 나는 이미지가 회전되어 있고 그것이 충분히 확실한 것처럼 왜 내 픽셀 데이터가 움직이고 있는지를 설명하기 위해 빠른 점검을하고있었습니다. –

답변

3

이미지가 UIImage로 제공되고 있지만 실제로는 근원 점이 다른 기본 Quartz CGImage 데이터를 사용하고 있습니다 (왼쪽 하단에 있습니다). 즉, 이미지를 사용할 때 그것은 옆으로 회전합니다.

UIImage를 수정하여 고정 된 UIImage를 반환하는 매개 변수로 호출 할 수있는 C 함수를 발견했습니다.

http://blog.logichigh.com/2008/06/05/uiimage-fix/

관련 문제