How to improve the quality of photos taken with CameraManager

The comparison is simple: I take a photo using my custom camera that uses CameraManager. Then I take the same photo with the default Galaxy Note 5 camera. The largest size available for CameraManager is 3264 by 1836 , so I use it and set the Samsung camera to the same resolution. results

  • Note 5: I can see the details in the photo.
  • CameraManager: I do not see the details. The image is poor quality.

Then I try to install CameraManager photos using

  captureBuilder.set(CaptureRequest.JPEG_QUALITY, (byte) 100); 

There is still no change. Well, there’s only one change: the file size of the photo taken with CameraManager is 2.3 MB (it was 0.5 MB), and the size of the Samsung photo (remains) is 1.6 MB. Thus, even with a large size, a photograph taken with CameraManager still has poor quality. Any ideas on how I can fix this problem: how to take a picture using CameraManager are of the same quality as when using the standard camera application that comes with note 5?

+6
source share
2 answers

These are some of the methods when we are working on the Camer manager, this method may help you.

The Android Camera application encodes a photo with the intention of being delivered to onActivityResult () as a small bitmap in additional functions, key β€œdata”. The following code retrieves this image and displays it in an ImageView.

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); mImageView.setImageBitmap(imageBitmap); } } private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image; } private void setPic() { // Get the dimensions of the View int targetW = mImageView.getWidth(); int targetH = mImageView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW/targetW, photoH/targetH); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); mImageView.setImageBitmap(bitmap); } 
+1
source

I think the quality is better in the Samsung camera app because it uses the Samsung Camera SDK . This is an extension of the Camera2 API.

The SDK provides useful advanced features (such as phase-autofocus). Try also to provide optical stabilization of the lens.

0
source

Source: https://habr.com/ru/post/1011674/


All Articles