使用AVCaptureSession的ios光学变焦

时间:2013-11-21 04:18:45

标签: ios barcode-scanner avcapturesession

您好我正在开发一个具有条形扫描选项的应用程序,所以我使用zbar但是我正在制作我自己的相机视图端口并将图像发送到zbar扫描仪,但我需要以编程方式缩放相机,我需要光学变焦。我能够进行数码变焦,但我需要光学变焦选项。有帮助吗? 为了制作相机视口,我正在使用AVCaptureSession。这是我的代码

-(void)initializecam{ 
AVCaptureSession *session = [[AVCaptureSession alloc] init];
//session.sessionPreset = AVCaptureSessionPresetMedium;
session.sessionPreset = AVCaptureSessionPresetPhoto;

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

captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[captureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];


[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

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];
_stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[_stillImageOutput setOutputSettings:outputSettings];

[session addOutput:_stillImageOutput];
[session startRunning];
}

1 个答案:

答案 0 :(得分:0)

您无法使用光学变焦,因为iOS设备目前没有此类功能。只看最新的iPhone 5s,它只有数码变焦。所以你需要外部设备来使用光学变焦。