Poor image quality when using a custom camera

I use a custom camera and work fine, but the problem is saving the image with very low (low) quality. To overcome this, I tried all the suggestions and implementations. For instance,

parameters.setJpegQuality(100); parameters.setPictureFormat(ImageFormat.JPEG); 

this does not work. After that i used

 List<Size> sizes = cameraParams.getSupportedPictureSizes(); Camera.Size size = sizes.get(0); for(int i=0;i<sizes.size();i++) { if(sizes.get(i).width > size.width) size = sizes.get(i); } cameraParams.setPictureSize(mPictureSize.width, mPictureSize.height); 

This also does not work. Its conservation with low quality is still.

Note. A camera preview shows the quality with good quality, but the problem is saving the captured image in the SDK folder.

Advanced help will be appreciated!

+6
source share
2 answers

Finally, my problem is resolved.

Here I set the parameters to preview the camera before I captured the image

  public void takePicture() { mCamera.takePicture(new ShutterCallback() { @Override public void onShutter() { } }, new PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { } }, new PictureCallback() { @Override public void onPictureTaken(final byte[] data, Camera camera) { data1 = data; if (mCamera != null) { mCamera.stopPreview(); } } }); } 

So, before I called this function in my fragment, I set the parameters before this method.

 mPreview.setParams(params);// This was the mistake what i have done ! mPreview.takePicture(); 

finally resolved after the removal of mPreview.setParams(params);

+5
source

I can show you ways to reset the preview size:

You must change the preview settings on the Camera.

 private void setImageSize() { Camera.Size size = CameraUtil.findClosetImageSize(mRxCamera.getNativeCamera(), PREFER_SIZE); mCamera.getNativeCamera().getParameters().setPictureSize(size.width, size.height); WIDTH = size.width; HEIGHT = size.height; } 

and after you need to resize the layout

 private void resetPreviewSize() { final boolean widthIsMax = mWidth > mHeight; final Camera.Size size = mCamera.getNativeCamera().getParameters().getPreviewSize(); final RectF rectDisplay = new RectF(); final RectF rectPreview = new RectF(); rectDisplay.set(0, 0, mWidth, mHeight); final int width = widthIsMax ? size.width : size.height; final int height = widthIsMax ? size.height : size.width; rectPreview.set(0, 0, width, height); final Matrix matrix = new Matrix(); matrix.setRectToRect(rectDisplay, rectPreview, Matrix.ScaleToFit.START); matrix.invert(matrix); matrix.mapRect(rectPreview); mCameraView.getLayoutParams().height = (int) (rectPreview.bottom); mCameraView.getLayoutParams().width = (int) (rectPreview.right); mCameraView.requestLayout(); } 

and if you need

 public static Camera.Size findClosetImageSize(Camera camera, Point preferSize) { int preferX = preferSize.x; int preferY = preferSize.y; Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> allSupportSizes = parameters.getSupportedPictureSizes(); Log.d(TAG, "all support Image size: " + dumpPreviewSizeList(allSupportSizes)); int minDiff = Integer.MAX_VALUE; int index = 0; for (int i = 0; i < allSupportSizes.size(); i++) { Camera.Size size = allSupportSizes.get(i); int x = size.width; int y = size.height; int diff = Math.abs(x - preferX) + Math.abs(y - preferY); if (diff < minDiff) { minDiff = diff; index = i; } } return allSupportSizes.get(index); } 
+1
source

All Articles