相机变焦不工作 [英] Camera zoom not working

查看:253
本文介绍了相机变焦不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是API 2.1和我的调试显示15的最大变焦值code此处不使相机变焦。我如何获得相机变焦?

 摄像头= Camera.open();
Camera.Parameters参数= camera.getParameters();
parameters.set(方向,肖像);
parameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_TWILIGHT);
INT变焦= parameters.getMaxZoom();
Log.d(TAG,放大+变焦);
parameters.setZoom(15);
camera.setParameters(参数);
 

解决方案

此功能依赖于你的Andr​​oid版本。 该方法parameters.getMaxZoom()已出现自:API级别8(Android 2.2的),所以如果你使用的Andr​​oid 2.1这个code将无法正常工作。 而另一件事。你应该用你的最大变焦类似的东西parameters.setZoom(变焦);而是使用常量parameters.setZoom(15);

此外,您需要检查用户的设备支持缩放。你可以做这样的(仅适用于Android 2.2及更高版本)

  Camera.Parameters参数= camera.getParameters();
   INT maxZoom = parameters.getMaxZoom();
   如果(parameters.isZoomSupported()){
      如果(变焦> = 0&功放;和缩放< maxZoom){
        parameters.setZoom(变焦);
      } 其他 {
        //变焦参数不正确
      }
   }
 

但是,当我知道有设置放大了Android 2.1,我仍在调查这个问题没有标准的API。

I am using the API 2.1 and my debug shows a max zoom value of 15. The code here does not make the camera zoom. How do I get the camera to zoom?

camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_TWILIGHT);
int zoom = parameters.getMaxZoom();
Log.d(TAG, "Zoom " + zoom);
parameters.setZoom(15);
camera.setParameters(parameters);

解决方案

This functionality depends on your Android version. The method parameters.getMaxZoom() has been appeared since: API Level 8 (Android 2.2), so if you use Android 2.1 this code won't work. And another thing. You should use your max zoom something like that parameters.setZoom(zoom); instead using constant parameters.setZoom(15);

Also you need to check that user's device support zooming. You can do it like this (only for Android 2.2 and higher)

   Camera.Parameters parameters = camera.getParameters();
   int maxZoom = parameters.getMaxZoom(); 
   if (parameters.isZoomSupported()) {
      if (zoom >=0 && zoom < maxZoom) {
        parameters.setZoom(zoom);
      } else {
        // zoom parameter is incorrect
      }
   }

But as I know there are no standard API for setting zoom in Android 2.1 I am still investigating this question.

这篇关于相机变焦不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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