不支持连续自动对焦模式时的Android自动对焦 [英] Android auto focus when continuous auto focus modes are not supported

查看:254
本文介绍了不支持连续自动对焦模式时的Android自动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个摄像头,我想使其连续自动对焦,其方式与手机的摄像头相同.我找到了FOCUS_MODE_CONTINUOUS_VIDEOFOCUS_MODE_CONTINUOUS_PICTURE模式,但是我正在测试的某些HTC Gingerbread手机不支持这些模式.

I have a camera in my app and I want to make it auto focus continuously in the same way that the phone's camera does it. I found the modes FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE, but they are not supported by some of the HTC Gingerbread phones I'm testing on.

这是我要确定是否可以使用以下模式的步骤:

This is what I'm doing to determine whether I can use these modes:

        Camera.Parameters parameters = mCamera.getParameters();
        List<String> supportedFocusModes = parameters.getSupportedFocusModes();

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
            supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        }
        else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        }
        else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
            // auto focus on request only
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        }

我在几种不同的Gingerbread HTC手机上运行,​​我没有恢复到连续模式,但得到了自动".这使我可以自动按需对焦(当我呼叫mCamera.autoFocus(null)时,但是如果用户移动照相机,照相机将不会重新对焦.

Running on several different Gingerbread HTC phones I don't get the continuous modes back, but I get "auto". This lets me auto focus on demand (when I call mCamera.autoFocus(null), but the camera will not refocus if the user moves the camera.

我无法将对焦模式设置为相机不支持的任何模式,如果我这样做,它会显示为空白.

I cannot set the focus mode to anything the camera does not support, and if I do it shows up blank.

我尝试的一种解决方案是在计时器上调用mCamera.autoFocus(null).即使照相机已经对焦,这也会导致照相机连续重新对焦.

One solution that I tried is to call mCamera.autoFocus(null) on a timer. This causes the camera to refocus continuously, even if it is already in focus.

有没有办法在这些手机上实现连续的自动对焦体验?当我在这些手机上查看HTC的摄像头应用程序时,它确实具有连续的自动对焦-当您在摄像头周围移动时会重新对焦,并且一旦图片清晰就不会保持重新对焦.

Is there a way to implement a continuous auto focus experience on these phones? When I look at HTCs camera app on these phones it does have continuous auto focus - as you move around the camera refocuses and does not keep refocusing once the picture is in focus.

推荐答案

我们需要支持多种手机.最终,我的解决方案是以不同的方式处理每种情况.

We had a requirement to support a very wide range of phones. My solution in the end was to handle each case differently.

对于没有连续自动对焦支持的手机,我实现了一个实用程序,可使用SensorManager收听加速度计并在用户移动相机时触发mCamera.autoFocus(...).

For the scenario of phones without continuous auto-focus support I implemented a utility to listen to the accelerometer using SensorManager and trigger mCamera.autoFocus(...) whenever the user moves the camera.

还有一些较旧的平板电脑仅支持固定焦点(谁会使用这种东西!),在这种情况下,需要立即拍摄照片,而不是在焦点回调上.

There were also some older tablets that only supported fixed focus (who would use such a thing!), in that case the picture needed to be taken immediately - not on the focus callback.

对于大多数现代手机,上面的代码段可以使用FOCUS_MODE_CONTINUOUS_PICTURE.

For most modern phones the code snippet above was fine to use FOCUS_MODE_CONTINUOUS_PICTURE.

这篇关于不支持连续自动对焦模式时的Android自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆