Java Code Examples for android.hardware.Camera#setPreviewDisplay()

The following examples show how to use android.hardware.Camera#setPreviewDisplay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraManager.java    From LLApp with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public void openDriver(SurfaceHolder holder) throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {
		theCamera = Camera.open();
		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
		if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
			setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
			requestedFramingRectWidth = 0;
			requestedFramingRectHeight = 0;
		}
	}
	configManager.setDesiredCameraParameters(theCamera);

	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
	reverseImage = prefs.getBoolean(KEY_REVERSE_IMAGE, false);
}
 
Example 2
Source File: CameraManager.java    From Android with MIT License 6 votes vote down vote up
/**
 * Initialize the camera
 */
public Camera initCamera(Activity activity, SurfaceHolder viewHolder) {
    this.viewHolder = viewHolder;
    Camera mCamera = getCameraInstance(0);
    try {
        setParametersCamera(activity, mCamera);
        // Determine whether to support flash
        List<String> features = mCamera.getParameters().getSupportedFlashModes();
        if (null == features || features.contains(Camera.Parameters.FLASH_MODE_ON)) {
            isLighting = false;
            isSupportedLight = true;
        }
        mCamera.setPreviewDisplay(viewHolder);
        mCamera.startPreview();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mCamera;
}
 
Example 3
Source File: CameraManager.java    From android-apps with MIT License 6 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public void openDriver(SurfaceHolder holder) throws IOException {
  Camera theCamera = camera;
  if (theCamera == null) {
    theCamera = Camera.open();
    if (theCamera == null) {
      throw new IOException();
    }
    camera = theCamera;
  }
  theCamera.setPreviewDisplay(holder);

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }
  configManager.setDesiredCameraParameters(theCamera);

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
  reverseImage = prefs.getBoolean(PreferencesActivity.KEY_REVERSE_IMAGE, false);
}
 
Example 4
Source File: CameraManager.java    From android-quick-response-code with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {
        theCamera = Camera.open();
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }
    configManager.setDesiredCameraParameters(theCamera);
}
 
Example 5
Source File: CameraFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void switchCamera(Camera camera) {
    setCamera(camera);
    try {
        camera.setPreviewDisplay(mHolder);
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
}
 
Example 6
Source File: CameraFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
public void switchCamera(Camera camera) {
    setCamera(camera);
    try {
        camera.setPreviewDisplay(mHolder);
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
    Camera.Parameters parameters = camera.getParameters();
    parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
    requestLayout();

    camera.setParameters(parameters);
}
 
Example 7
Source File: CameraManager.java    From YZxing with Apache License 2.0 5 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    OpenCamera theCamera = camera;
    if (theCamera == null) {
        theCamera = OpenCameraInterface.open(requestedCameraId);
        if (theCamera == null) {
            throw new IOException("Camera.open() failed to return object from driver");
        }
        camera = theCamera;
    }

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight
                    , requestedFramingRectTopPadding > 0 ? requestedFramingRectTopPadding : -1);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }

    Camera cameraObject = theCamera.getCamera();
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
    }
    cameraObject.setPreviewDisplay(holder);

}
 
Example 8
Source File: JCameraView.java    From CameraView with Apache License 2.0 5 votes vote down vote up
private void setStartPreview(Camera camera, SurfaceHolder holder) {
    try {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPictureFormat(ImageFormat.JPEG);
        List<Camera.Size> sizeList = parameters.getSupportedPreviewSizes();//获取所有支持的camera尺寸
        Iterator<Camera.Size> itor = sizeList.iterator();
        while (itor.hasNext()) {
            Camera.Size cur = itor.next();
            Log.i("CJT", "所有的  width = " + cur.width + " height = " + cur.height);
            if (cur.width >= width&& cur.height >= height) {
                width = cur.width;
                height = cur.height;
            }
        }
        Log.i("size", "width : height" + width + " : " + height + " ==== " + getWidth() + " : " + getHeight());
        parameters.setPreviewSize(width, height);//把camera.size赋值到parameters
        parameters.setPictureSize(width, height);
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        camera.setParameters(parameters);

        camera.setPreviewDisplay(holder);
        camera.setDisplayOrientation(90);
        camera.startPreview();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: CameraManager.java    From camera2QRcodeReader with MIT License 5 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder, int viewWidth, int viewHeight) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {
        theCamera = new OpenCameraManager().build().open();
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera, viewWidth, viewHeight);
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }

}
 
Example 10
Source File: CameraFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void switchCamera(Camera camera) {
    setCamera(camera);
    try {
        camera.setPreviewDisplay(mHolder);
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
}
 
Example 11
Source File: CameraManager.java    From moVirt with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {

        theCamera = OpenCameraInterface.open(requestedCameraId);
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }
}
 
Example 12
Source File: CameraManager.java    From ScanZxing with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder)
		throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {

		if (requestedCameraId >= 0) {
			theCamera = OpenCameraInterface.open(requestedCameraId);
		} else {
			theCamera = OpenCameraInterface.open();
		}

		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
		if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
			setManualFramingRect(requestedFramingRectWidth,
					requestedFramingRectHeight);
			requestedFramingRectWidth = 0;
			requestedFramingRectHeight = 0;
		}
	}

	Camera.Parameters parameters = theCamera.getParameters();
	String parametersFlattened = parameters == null ? null : parameters
			.flatten(); // Save these, temporarily
	try {
		configManager.setDesiredCameraParameters(theCamera, false);
	} catch (RuntimeException re) {
		// Driver failed
		Log.w(TAG,
				"Camera rejected parameters. Setting only minimal safe-mode parameters");
		Log.i(TAG, "Resetting to saved camera params: "
				+ parametersFlattened);
		// Reset:
		if (parametersFlattened != null) {
			parameters = theCamera.getParameters();
			parameters.unflatten(parametersFlattened);
			try {
				theCamera.setParameters(parameters);
				configManager.setDesiredCameraParameters(theCamera, true);
			} catch (RuntimeException re2) {
				// Well, darn. Give up
				Log.w(TAG,
						"Camera rejected even safe-mode parameters! No configuration");
			}
		}
	}

}
 
Example 13
Source File: CameraManager.java    From zxingfragmentlib with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  Camera theCamera = camera;
  if (theCamera == null) {

    if (requestedCameraId >= 0) {
      theCamera = OpenCameraInterface.open(requestedCameraId);
    } else {
      theCamera = OpenCameraInterface.open();
    }
    
    if (theCamera == null) {
      throw new IOException();
    }
    camera = theCamera;
  }
  theCamera.setPreviewDisplay(holder);

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera.Parameters parameters = theCamera.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = theCamera.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        theCamera.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }

}
 
Example 14
Source File: CameraManager.java    From AndroidWebServ with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {
        theCamera = new OpenCameraManager().build().open();
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }

}
 
Example 15
Source File: CameraManager.java    From ScanZbar with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * <p>
 * <p>
 * The surface object which the camera will draw preview frames
 * into.
 *
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {
        theCamera = Camera.open();
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    // 设置摄像头预览view
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
    // temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }

}
 
Example 16
Source File: CameraManager.java    From ZXingProject with MIT License 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {

		if (requestedCameraId >= 0) {
			theCamera = OpenCameraInterface.open(requestedCameraId);
		} else {
			theCamera = OpenCameraInterface.open();
		}

		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
	}

	Camera.Parameters parameters = theCamera.getParameters();
	String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
																					// these,
																					// temporarily
	try {
		configManager.setDesiredCameraParameters(theCamera, false);
	} catch (RuntimeException re) {
		// Driver failed
		Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
		Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
		// Reset:
		if (parametersFlattened != null) {
			parameters = theCamera.getParameters();
			parameters.unflatten(parametersFlattened);
			try {
				theCamera.setParameters(parameters);
				configManager.setDesiredCameraParameters(theCamera, true);
			} catch (RuntimeException re2) {
				// Well, darn. Give up
				Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
			}
		}
	}

}
 
Example 17
Source File: CameraManager.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  OpenCamera theCamera = camera;
  if (theCamera == null) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    camera = theCamera;
  }

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);

}
 
Example 18
Source File: CameraManager.java    From BarcodeScanner with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder)
		throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {
		// 获取手机背面的摄像头
		theCamera = OpenCameraInterface.open();
		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}

	// 设置摄像头预览view
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
		if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
			setManualFramingRect(requestedFramingRectWidth,
					requestedFramingRectHeight);
			requestedFramingRectWidth = 0;
			requestedFramingRectHeight = 0;
		}
	}

	Camera.Parameters parameters = theCamera.getParameters();
	String parametersFlattened = parameters == null ? null : parameters
			.flatten(); // Save
						// these,
						// temporarily
	try {
		configManager.setDesiredCameraParameters(theCamera, false);
	}
	catch (RuntimeException re) {
		// Driver failed
		Log.w(TAG,
				"Camera rejected parameters. Setting only minimal safe-mode parameters");
		Log.i(TAG, "Resetting to saved camera params: "
				+ parametersFlattened);
		// Reset:
		if (parametersFlattened != null) {
			parameters = theCamera.getParameters();
			parameters.unflatten(parametersFlattened);
			try {
				theCamera.setParameters(parameters);
				configManager.setDesiredCameraParameters(theCamera, true);
			}
			catch (RuntimeException re2) {
				// Well, darn. Give up
				Log.w(TAG,
						"Camera rejected even safe-mode parameters! No configuration");
			}
		}
	}

}
 
Example 19
Source File: CameraManager.java    From BarcodeEye with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 * @throws InterruptedException
 */
public synchronized void openDriver(SurfaceHolder holder)
        throws IOException, InterruptedException {
    Camera theCamera = camera;
    if (theCamera == null) {
        theCamera = OpenCameraInterface.open();
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth,
                    requestedFramingRectHeight);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters
            .flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG,
                "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: "
                + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG,
                        "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }

}
 
Example 20
Source File: CameraManager.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 * 
 * @param holder
 *            The surface object which the camera will draw preview frames
 *            into.
 * @throws IOException
 *             Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
	Camera theCamera = camera;
	if (theCamera == null) {

		if (requestedCameraId >= 0) {
			theCamera = OpenCameraInterface.open(requestedCameraId);
		} else {
			theCamera = OpenCameraInterface.open();
		}

		if (theCamera == null) {
			throw new IOException();
		}
		camera = theCamera;
	}
	theCamera.setPreviewDisplay(holder);

	if (!initialized) {
		initialized = true;
		configManager.initFromCameraParameters(theCamera);
	}

	Camera.Parameters parameters = theCamera.getParameters();
	String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
																					// these,
																					// temporarily
	try {
		configManager.setDesiredCameraParameters(theCamera, false);
	} catch (RuntimeException re) {
		// Driver failed
		Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
		Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
		// Reset:
		if (parametersFlattened != null) {
			parameters = theCamera.getParameters();
			parameters.unflatten(parametersFlattened);
			try {
				theCamera.setParameters(parameters);
				configManager.setDesiredCameraParameters(theCamera, true);
			} catch (RuntimeException re2) {
				// Well, darn. Give up
				Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
			}
		}
	}

}