Camera setPreviewDisplay - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:setPreviewDisplay
        public void surfaceCreated(SurfaceHolder holder) { 
            camera=Camera.open(); 
 
            try  
            { 
            	camera.setPreviewDisplay(previewHolder); 
            } 
            catch (Throwable t) { 
                     
            } 
        } 
 
		public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h) 
		{ 
			//Parameters params = camera.getParameters(); 
			//params.setPreviewSize(w, h); 
			//params.setPictureFormat(PixelFormat.JPEG); 
	        //camera.setParameters(params); 
	        camera.startPreview(); 
		} 
10
CodeRank
This code example shows how to use the following methods:getParameters, setParameters, setPreviewDisplay, startPreview
 
} 
 
 
private void startCamera(SurfaceHolder sh, int width, int height) {
    Camera.Parameters p = mCam.getParameters();
    // Camera.Size s = p.getSupportedPreviewSizes().get(0); 
    p.setPreviewSize(width, height);
 
    mCam.setParameters(p);
 
    try { 
        mCam.setPreviewDisplay(sh);
    } catch (Exception e) {
    } 
 
    mCam.startPreview();
} 
 
private void stopCamera() { 

10
CodeRank
This code example shows how to use the following methods:getParameters, setParameters, setPreviewDisplay
      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 { 

10
CodeRank
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:setPreviewDisplay
	SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
		public void surfaceCreated(SurfaceHolder holder) { 
			camera=Camera.open(); 
			 
			try { 
				camera.setPreviewDisplay(previewHolder); 
			} 
			catch (Throwable t) { 
				Log.e("Photographer", 
							"Exception in setPreviewDisplay()", t); 
				Toast 
					.makeText(Photographer.this, t.getMessage(), 
										Toast.LENGTH_LONG) 
					.show(); 
			} 
		} 
		 
		public void surfaceChanged(SurfaceHolder holder, 
															 int format, int width, 
															 int height) { 
10
CodeRank
This code example shows how to use the following methods:getParameters, setParameters, setPreviewDisplay, startPreview
		if(!isView){//ÊÇ·ñÒѾ­ÏÔʾ
    		myCamera = Camera.open();
    	} 
		if(myCamera != null && !isView){
            try { 
            	Camera.Parameters myParameters = myCamera.getParameters();
            	myParameters.setPictureFormat(PixelFormat.JPEG);
            	myParameters.setPreviewSize(320, 445);//ÆÁÄ»´óС
            	myCamera.setParameters(myParameters);
    			myCamera.setPreviewDisplay(mySurfaceHolder);
    			myCamera.startPreview();//Á¢¼´ÔËÐÐPreview
    		}  
            catch (IOException e) {//²¶»ñÒì³£
    			e.printStackTrace();//´òÓ¡´íÎóÐÅÏ¢
    		}   
            isView = true;//½«ÊÇ·ñÏÔʾ±ê־λÉèÖóÉtrue
    	} 
	} 
	@Override 
	public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {}
10
CodeRank
This code example shows how to use the following methods:setPreviewDisplay, startPreview
 
	public void surfaceCreated(SurfaceHolder mholder) {
		// The Surface has been created, now tell the camera where to draw the 
		// preview. 
		try { 
			mCamera.setPreviewDisplay(mHolder);
			mCamera.startPreview();
			Log.d(LOG_TAG, "Preview created");
 
		} catch (IOException e) {
			Log.d(LOG_TAG, "Error setting camera preview: " + e.getMessage());
		} catch (Exception e) {
			Log.d(LOG_TAG, "Error - surfaceCreated: " + e.getMessage());
		} 
	} 
 
	public void surfaceDestroyed(SurfaceHolder mholder) {
		// empty. Take care of releasing the camera preview in your activity 
		mCamera.stopPreview();
		Log.d(LOG_TAG, "Preview destroyed");
9
CodeRank
This code example shows how to use the following methods:setPreviewDisplay
    } 
 
    public void surfaceCreated(SurfaceHolder holder) {
        // The Surface has been created, now tell the camera where to draw the preview. 
        try { 
            mCamera.setPreviewDisplay(holder);
        } catch (IOException e) {
            Log.d("DBG", "Error setting camera preview: " + e.getMessage());
        } 
    } 
 
    public void surfaceDestroyed(SurfaceHolder holder) {
        // Camera preview released in activity 
    } 
 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        /* 
         * If your preview can change or rotate, take care of those events here. 
         * Make sure to stop the preview before resizing or reformatting it. 
         */ 
10
CodeRank
This code example shows how to use the following methods:getParameters, setParameters, setPreviewDisplay, startPreview
     
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
 
    	if(camera!=null)
        { 
	    	Camera.Parameters p = camera.getParameters();
	        // Camera.Size s = p.getSupportedPreviewSizes().get(0); 
	        p.setPreviewSize(width, height);
	 
	        camera.setParameters(p);
	 
	        try { 
	        	camera.setPreviewDisplay(holder);
	        } catch (Exception e) {
	        } 
	 
	        camera.startPreview();
        } 
    } 
     

10
CodeRank
This code example shows how to use the following methods:setPreviewDisplay
    SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
            public void surfaceCreated(SurfaceHolder holder) { 
                camera=Camera.open(); 
 
                try { 
                    camera.setPreviewDisplay(previewHolder); 
                } 
                catch (Throwable t) { 
                    Toast 
                        .makeText(CameraFavorite.this, t.getMessage(), Toast.LENGTH_LONG) 
                        .show(); 
                } 
            } 
 
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 
                Camera.Parameters parameters=camera.getParameters(); 
 
                parameters.setPreviewSize(width, height); 
                parameters.setPictureFormat(PixelFormat.JPEG); 
                try { 
10
CodeRank

Related Camera setPreviewDisplay Questions & Answers:

setPreviewDisplay Method Overview
Sets the Surface to be used for live preview.
See Code Examples for other Android Camera Methods: