Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
458 views
in Technique[技术] by (71.8m points)

android - Camera zoom not working

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...