iOS 5 - AVCaptureDevice 设置焦点和对焦模式冻结实时相机图片
自 iOS 4 以来,我使用以下方法来设置焦点:
- (void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [[self captureInput] device];
NSError *error;
if ([device isFocusModeSupported:AVCaptureFocusModeAutoFocus] &&
[device isFocusPointOfInterestSupported])
{
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
NSLog(@"Error: %@", error);
}
}
}
在 iOS 4 设备上,这可以正常工作。但在 iOS 5 上,实时摄像头画面冻结,几秒钟后就完全变黑了。没有抛出异常或错误。
如果我注释掉 setFocusPointOfInterest 或 setFocusMode ,则不会发生该错误。所以它们两者的结合就会导致这种行为。
I'm using the following method to set point of focus since iOS 4:
- (void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [[self captureInput] device];
NSError *error;
if ([device isFocusModeSupported:AVCaptureFocusModeAutoFocus] &&
[device isFocusPointOfInterestSupported])
{
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
NSLog(@"Error: %@", error);
}
}
}
On iOS 4 devices this works without any problems. But on iOS 5 the live camera feed freezes and after some seconds gets completely black. There is no exception or error thrown.
The error won't occur if I comment out either setFocusPointOfInterest or setFocusMode. So the combination of them both will lead to this behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您给出的 setFocusPointOfInterest: 函数的观点不正确。这就是它崩溃的原因。
将此方法添加到您的程序中并使用此函数返回的值
The point you've given the setFocusPointOfInterest: function is incorrect. It's the reason why it's crashing.
Add this method to your program and use the value returned by this function
我想为 @Louis 的回答提供一些额外的信息。
根据 Apple 的文档(请注意粗体部分):
在计算
FocusPointOfInterest
时,我们应该考虑方向。I want to give some additional info to @Louis 's answer.
According to Apple's documents (Please pay attention to the bold part):
We should involve the orientation when calculate
FocusPointOfInterest
.