Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase quality of photos taken with CameraManager

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

  • Note 5: I can see details in the photo
  • CameraManager: I cannot see details. The image is of low quality.

Then I try setting the CameraManager photos with

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

Still no change. Well only one change: the file size of the photo taken with CameraManager becomes 2.3MB (it used to be 0.5MB) while the size of the Samsung photo (remains) 1.6MB. So even with the larger size, the photo taken with CameraManager is still of lower quality. Any ideas how I might fix this problem: How do I make the photo taken with CameraManager have the same quality as the one taken with the default Camera app that comes with the Note 5?

like image 845
Nouvel Travay Avatar asked Oct 25 '16 00:10

Nouvel Travay


People also ask

How can I improve the quality of a photo?

One-Tap Image Enhancer Fotor's powerful image enhancer can help you improve your photo quality with only one click. Just upload your image and click “1-Tap Enhance” button, and Fotor will automatically detect and correct the lightings and color, improve details, and repair blurry for your photo in real time.


1 Answers

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

The Android Camera application encodes the photo in the Intent delivered to onActivityResult() as a small Bitmap in the extras, under the 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);
}
like image 164
Vijay Kumar M Avatar answered Oct 29 '22 08:10

Vijay Kumar M