Code example for Camera.CameraInfo

Methods: getCameraInfo

0
     
    /** 
     * Set orientation from portrait / landscape. 
     */ 
    public void setCameraDisplayOrientation() { 
	     CameraInfo info = new CameraInfo();
	     Camera.getCameraInfo(0, info);
	     int rotation = ((Activity)getContext()).getWindowManager().getDefaultDisplay().getRotation();
	     int degrees = 0;
	     switch (rotation) {
	         case Surface.ROTATION_0: degrees = 0; break;
	         case Surface.ROTATION_90: degrees = 90; break;
	         case Surface.ROTATION_180: degrees = 180; break;
	         case Surface.ROTATION_270: degrees = 270; break;
	     } 
 
	     int result;
	     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
	         result = (info.orientation + degrees) % 360;
	         result = (360 - result) % 360;  // compensate the mirror
	     } else {  // back-facing