I am new to java and android development. I am developing an application with a camera view in a frameLayout window. My application is intended for orientation in portrait orientation, but the window is in landscape mode, as shown in the figure>. As usual, viewing the default camera in the landscape, so I do camera.setDisplayOrientation (90); to rotate it.
My problem is that when I rotate the image in portrait mode in the landscape window, it is distorted (Pinched). can any1 help me solve this problem, can any1 provide me with a solution to crop borders to achieve the required ratio.
! Im a new user for stackoverflow, so m is not allowed to upload image to others, I can show u.
___________________________________________ |____________Notification bar_______________| | | | My Application | |___________________________________________| | | | | | | | | | | | | | | | camera View | | ____________________ | | | | | | | | | | | | | | | | | | | | | | |____________________| | | | | | | | | | | | | | | | | | |___________________________________________|
code:
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if(preview_running){ camera.stopPreview(); preview_running = false; } Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> sizes = parameters.getSupportedPreviewSizes(); int mFrameWidth = width; int mFrameHeight = height; { double minDiff = Double.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - height) < minDiff) { mFrameWidth = size.width; mFrameHeight = size.height; minDiff = Math.abs(size.height - height); } } } if( (width*height) != 0){ parameters.setPreviewSize(mFrameHeight, mFrameWidth); System.out.println("TEST 1"); } camera.setDisplayOrientation(90); camera.setParameters(parameters); camera.startPreview(); preview_running = true; }
source share