camera Zoom - Android android.hardware

Android examples for android.hardware:Camera Zoom

Description

camera Zoom

Demo Code

import android.hardware.Camera;
import android.hardware.Camera.Parameters;

public class Main {

  private static final int MIN_ZOOM = 0;
  private static final int MAX_ZOOM = 6;
  protected static void cameraZoom(Camera cam, int dir) {
    Parameters p = cam.getParameters();//from  w w w  .  j  av a2  s.  c  o  m
    String zoomSupportedString = p.get("zoom-supported");
    if (zoomSupportedString != null && !Boolean.parseBoolean(zoomSupportedString))
      return;

    int zoom = getZoom(p);
    p.set("zoom", adjustZoom(zoom + dir));

    cam.setParameters(p);
  }

  private static int getZoom(Parameters p) {
    try {
      return Integer.valueOf(p.get("zoom"));
    } catch (NumberFormatException e) {
      return 0;
    }
  }

  private static int adjustZoom(int zoom) {
    if (zoom < MIN_ZOOM)
      return MIN_ZOOM;
    else if (zoom > MAX_ZOOM)
      return MAX_ZOOM;

    return zoom;
  }

}

Related Tutorials