Note that there are some explanatory texts on larger screens.

plurals
  1. POfullScreen Camera Preview without distortion/stretching
    text
    copied!<p>I have a cameraPreview class (see below) that is launching fullscreen and landscape... but the image is getting stretched/ and distorted.. is there a way to get this preview to remain fullscreen but not distort? </p> <p>camLayer:</p> <pre><code>public class CamLayer extends SurfaceView implements SurfaceHolder.Callback { Camera camera; SurfaceHolder previewHolder; String camID; private static final String TAG = "Cam Preview"; public CamLayer(Context context, String facing) { super(context); camID = facing; previewHolder = this.getHolder(); previewHolder.addCallback(this); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { startCamera(); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Parameters params = camera.getParameters(); //params.setPreviewSize(width, height); //params.setPictureFormat(PixelFormat.JPEG); camera.setParameters(params); camera.startPreview(); } public void surfaceDestroyed(SurfaceHolder arg0) { stopCamera(); } public void onResume() { startCamera(); } public void onPause() { stopCamera(); } public void stopCamera(){ System.out.println("stopCamera method"); if (camera != null){ camera.stopPreview(); camera.setPreviewCallback(null); camera.release(); camera = null; previewHolder.removeCallback(this); previewHolder = null; } } private void startCamera(){ if(camID.equals("front")){ camera=Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); }else{ camera=Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK); } try { camera.setPreviewDisplay(previewHolder); } catch (Throwable e){ Log.w("TAG,", "failed create surface !?!?"); } } public void draw(Canvas canvas) { super.draw(canvas); Paint p = new Paint(Color.RED); Log.d(TAG, "draw"); canvas.drawText("PREVIEW", canvas.getWidth() / 2, canvas.getHeight() / 2, p); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload