我正在努力解决的缩放问题仍然存在。我尝试按照link1和link2的代码使用 AVCaptureSession 获取图像。
一切都很好,除了当我尝试实现相机变焦时,事情并没有按我的意愿执行。
我尝试在 AVCaptureDevice 对象上使用 videoZoomFactor 方法,如下面的代码所示。
你有什么建议为什么 videoZoomFactor 没有任何效果?
您将如何按预期使用 AVCaptureSession 为静止图像采集创建缩放?
- (void)addVideoInput {
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice) {
// SOMEHOW NOT HAVING AN EFFECT AT ALL - WHY ?????
if ([videoDevice lockForConfiguration:nil]) {
float zoomFactor = videoDevice.activeFormat.videoZoomFactorUpscaleThreshold;
[videoDevice setVideoZoomFactor:zoomFactor];
// [videoDevice setVideoZoomFactor:3];
// videoDevice.videoZoomFactor = 3;
[videoDevice unlockForConfiguration];
}
// that all works again nicely...
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
if ([[self captureSession] canAddInput:videoIn]) {
[[self captureSession] addInput:videoIn];
}
else
NSLog(@"Couldn't add video input");
}
else
NSLog(@"Couldn't create video input");
}
else
NSLog(@"Couldn't create video capture device");
}