2011-12-23 12 views
1

は思っ:のiOS 5リアカメラのプレビュー

私はカメラのプレビューを表示するための様々なソリューションを見てきました。フルスクリーンモードでこれを行うのは比較的単純ですが、私がしたいのは、画面の50%に拡大し、グラフィック(オーバーレイではなく別のグラフィックカメラのプレビューの左側には同じスペースがあります)。基本的には、ユーザがカメラプレビューとグラフィックとを比較できるようにすることです。私が知っておくべきことだから、

は、次のとおりです。 a)は低解像度 Bにカメラのプレビューをスケーリングすることが可能である)、それは、オーバーレイ Cではない別のグラフィックでiPadの画面を共有することができます)aとbが真であれば、私が指し示すかもしれないソースの例はありますか?

ありがとうございます!

答えて

0

あなたは、次のコードを使用することができます。

previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession]; 
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
previewLayer.opaque = YES; 
previewLayer.contentsScale = self.view.contentScaleFactor; 
previewLayer.frame = self.view.bounds; 
previewLayer.needsDisplayOnBoundsChange = YES; 
[self.view.layer addSublayer:previewLayer]; 

だけでプレビュー層に別のフレームを設定するためのライン5を交換してください。 あなたはこのコードを使用しての提案のための

captureSession = [[AVCaptureSession alloc] init]; 

if(!captureSession) 
{ 
    NSLog(@"Failed to create video capture session"); 
    return NO; 
} 

[captureSession beginConfiguration]; 

captureSession.sessionPreset = AVCaptureSessionPreset640x480; 

AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
videoDevice.position = AVCaptureDevicePositionFront; 

if(!videoDevice) 
{ 
    NSLog(@"Couldn't create video capture device"); 
    [captureSession release]; 
    captureSession = nil; 
    return NO; 
} 

if([videoDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) 
{ 
    NSError *deviceError = nil; 

    if([videoDevice lockForConfiguration:&deviceError]) 
    { 
     [videoDevice setFocusMode:AVCaptureFocusModeContinuousAutoFocus]; 
     [videoDevice unlockForConfiguration]; 
    } 
    else 
    { 
     NSLog(@"Couldn't lock device for configuration"); 
    } 
} 

NSError *error; 
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; 

if(!videoIn) 
{ 
    NSLog(@"Couldn't create video capture device input: %@ - %@", [error localizedDescription], [error localizedFailureReason]); 
    [captureSession release]; 
    captureSession = nil; 
    return NO; 
} 

if(![captureSession canAddInput:videoIn]) 
{ 
    NSLog(@"Couldn't add video capture device input"); 
    [captureSession release]; 
    captureSession = nil; 
    return NO; 
} 

[captureSession addInput:videoIn]; 
[captureSession commitConfiguration]; 
+0

感謝をcaptureSessionを作成することができます - 私はそれを試してみますよ! –