android – What codes to use to add zoom to the camera?

Question:

My group is making a camera app. We just don't know what code to use to add zoom to the camera. Does anyone know how to do it?

Answer:

This below will work if the user's Android is:

  • API 8+

   Camera.Parameters parameters = camera.getParameters();
   int maxZoom = parameters.getMaxZoom(); 
      if (parameters.isZoomSupported()) {
        if (zoom >=0 && zoom < maxZoom) {
         parameters.setZoom(zoom);
      } else {
        // zoom parameter incorreto
      }
     }
Scroll to Top
AllEscort