iOS 5 后置摄像头非全屏模式预览

问题描述 投票:0回答:1

我只是想知道这是否可能:

我一直在寻找各种显示相机预览的解决方案;虽然在全屏模式下这样做相对简单,但我想做的是将其缩放到屏幕的 50% 并与图形并排呈现(不是覆盖,而是一个单独的图形)位于相机预览的左侧,占用相同的空间)。基本上目的是让用户将相机预览与图形进行比较。

所以,我需要知道的是:

  1. 是否可以将相机预览缩放到较低的分辨率
  2. 它可以与另一个非叠加图形共享 iPad 上的屏幕吗
  3. 如果 1 和 2 为真,有没有可以给我指出的示例来源?
ios camera scale preview
1个回答
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

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];
© www.soinside.com 2019 - 2024. All rights reserved.