Camera zoom not working

前端 未结 5 1398
盖世英雄少女心
盖世英雄少女心 2020-12-15 14:39

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 = Came         


        
5条回答
  •  眼角桃花
    2020-12-15 15:15

    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.

提交回复
热议问题