Android Camera - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Camera class.

This code example shows how to use the following methods:setPreviewDisplay, startPreview
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    } 
 
    public void surfaceCreated(SurfaceHolder holder) {
        try { 
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        } catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        } 
    } 
 
    public void surfaceDestroyed(SurfaceHolder holder) {
    } 
     
 
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
 
        if (mHolder.getSurface() == null){
          return; 
10
CodeRank
This code example shows how to use the following methods:getParameters, setParameters
	 *  
	 * @param state			The requested state 
	 *  
	 */ 
	protected void toggleTorch(boolean state) {
		mParameters = mCamera.getParameters();
 
		// Make sure that torch mode is supported 
		// 
		if ( this.isCapable() ) {
			if (state) {
				mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
			} else { 
				mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
			} 
 
			// Commit the camera parameters 
			// 
			mCamera.setParameters(mParameters);
 

10
CodeRank
This code example shows how to use the following methods:getParameters, stopPreview
    { 
        Log.e(TAG, "surfaceChanged");
 
        // XXX stopPreview() will crash if preview is not running 
        if (mPreviewRunning) {
            mCamera.stopPreview();
        } 
 
        Camera.Parameters p = mCamera.getParameters();
        p.setPreviewSize(w, h);
        mCamera.setParameters(p);
        try { 
			mCamera.setPreviewDisplay(holder);
		} catch (IOException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
        mCamera.startPreview();
        mPreviewRunning = true;
    } 
10
CodeRank
This code example shows how to use the following methods:stopPreview
    if (autoFocusManager != null) {
      autoFocusManager.stop();
      autoFocusManager = null;
    } 
    if (camera != null && previewing) {
      camera.stopPreview();
      previewCallback.setHandler(null, 0);
      previewing = false;
    } 
  } 
 
  /** 
   * Convenience method for {@link com.google.zxing.client.android.CaptureActivity} 
   */ 
  public synchronized void setTorch(boolean newSetting) {
    if (camera != null) {
      if (autoFocusManager != null) {
        autoFocusManager.stop();
      } 
      configManager.setTorch(camera, newSetting);
10
CodeRank
This code example shows how to use the following methods:getParameters
		} 
		return new Size(neww, newh);
	} 
	 
	public boolean isAutoFocusSupported(android.hardware.Camera camera) {
		String focus_mode = camera.getParameters().getFocusMode();
		boolean auto_focus_supported = false;
		if ( focus_mode != null ) {
			auto_focus_supported = (focus_mode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO)) || (focus_mode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_MACRO));
		} 
		return auto_focus_supported;
	} 
	 
	public boolean isFlashModeSupported(android.hardware.Camera camera, String flash_mode) {
		String camera_flash_mode = camera.getParameters().getFlashMode();
		boolean flash_supported = false;
		if ( camera_flash_mode != null ) {
			List<String> modes_list = camera.getParameters().getSupportedFlashModes();
			if (modes_list != null) {
				if (modes_list.contains(flash_mode)) {
10
CodeRank
This code example shows how to use the following methods:startPreview
    } 
  } 
   
  private void startPreview() { 
    if (cameraConfigured && camera!=null) {
      camera.startPreview();
      inPreview=true;
    } 
  } 
   
  SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
    public void surfaceCreated(SurfaceHolder holder) { 
      // no-op -- wait until surfaceChanged() 
    } 
     
    public void surfaceChanged(SurfaceHolder holder, 
                               int format, int width, 
                               int height) { 
      initPreview(width, height); 
      startPreview(); 
10
CodeRank
This code example shows how to use the following methods:getParameters, setDisplayOrientation, setParameters, setPreviewDisplay, startPreview
			return; 
		} 
 
		// stop preview before making changes 
		try { 
			mCamera.stopPreview();
		} catch (Exception e) {
			Log.d(LOG_TAG, "Unable to stop preview");
		} 
		Parameters p = mCamera.getParameters();
		mCamera.setDisplayOrientation(90);
		mCamera.setParameters(p);
		Log.d(LOG_TAG, "Surface changed");
 
		// set preview size and make any resize, rotate or 
		// reformatting changes here 
 
		// start preview with new settings 
		try { 
			mCamera.setPreviewDisplay(mholder);

10
CodeRank
This code example shows how to use the following methods:setParameters
    /** 
     * Helper method for setting the camera parameters 
     */ 
    public void setParameters(Parameters params) {
        try { 
            mCamera.setParameters(params);
        } catch (Exception e) {
            Log.e(TAG, "Error setting camera parameters");
        } 
    } 
 
    /** 
     * Helper method for starting up the camera preview 
     */ 
    public void startCameraPreview(SurfaceHolder surfaceHolder) throws Exception {
        mCamera.setErrorCallback(mCameraErrorCallback);
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();
        Thread.sleep(WAIT_GENERIC);
    } 
10
CodeRank
This code example shows how to use the following methods:getParameters, setParameters, setPreviewDisplay, startPreview, stopPreview
10
CodeRank
This code example shows how to use the following methods:addCallbackBuffer
            } 
            */ 
        } 
         
        // re-enqueue this buffer 
        mCamera.addCallbackBuffer(data);
    } 
 
    public void surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, now tell the camera where to draw the preview. 
        try { 
            mCamera.addCallbackBuffer(previewData);
            Camera.Parameters p = mCamera.getParameters();
            p.setPreviewFormat(ImageFormat.YV12);
            mCamera.setParameters(p);
            mCamera.setPreviewCallbackWithBuffer(this);
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        } catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
10
CodeRank

Related Android Camera Questions & Answers:

Other Android Camera Examples

12:	public class MakePhotoActivity extends Activity {
13:	  private final static String DEBUG_TAG = "MakePhotoActivity";
14:	  private Camera camera;
15:	  private int cameraId = 0;
16:

Read More

17:		ImageButton btnSwitch;
18:	
19:		private Camera camera;
20:		private boolean isFlashOn;
21:		private boolean hasFlash;

Read More

17:		ImageButton btnSwitch;
18:	
19:		private Camera camera;
20:		private boolean isFlashOn;
21:		private boolean hasFlash;

Read More

See Code Examples for Android Camera Methods: