Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...