uCrop icon indicating copy to clipboard operation
uCrop copied to clipboard

Improve Output Image Quality

Open VivekKannaV opened this issue 6 years ago • 6 comments

After Processing Crop & rotate, Image output quality got very poor despite of choosing lossless compression (PNG).

We'r looking to use for documents, it's look unfair to read after crop the document.

Even we didn't crop / rotate, we just pass the image into UCrop but the output has been very poor.

Kindly looking for an awesome output from you.

Note: Output file size doesn't matter upto 2MB

VivekKannaV avatar Feb 05 '18 07:02 VivekKannaV

Try setting setMaxBitmapSize to something like 10000; I don't know what the number represents but it improved the quality

UCrop.Options options = new UCrop.Options();
            options.setCompressionQuality(100);
            options.setMaxBitmapSize(10000);

                UCrop.of(imageUri, Uri.fromFile(new File(getCacheDir(),"temp.jpg")))
                        .withOptions(options)
                                                .start(MainActivity.this);

musasystem avatar Feb 22 '18 16:02 musasystem

@VivekKannaV Hello! Did you solve it?

Legementarion avatar Apr 27 '18 08:04 Legementarion

I faced the same problem and found out that this was happening because(Bitmap) data.getExtras().get("data") from onActivityResult was referring to a thumbnail image when I was taking picture from camera.

Add the following code before start of your camera Intent. This will store the reference of the real image to imareUri

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

File file = new File(Environment.getExternalStorageDirectory(), "/your_app_Name/Images" + "/photo_" + timeStamp + ".jpg");
imageUri = Uri.fromFile(file);

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, IMAGE_FROM_CAMERA);

Now use the imageUri and feed it to UCrop

UCrop.of(imageUri,Uri.fromFile(new File(getCacheDir(), destinationFileName))).withOptions(options).start(YourActivity.this);

If you want to further improve the quality of the image you can do

options.setMaxBitmapSize(10000);

before starting UCrop activity.

Hope this helps

Ashu2k avatar Jun 30 '18 10:06 Ashu2k

There is a more simple solution to this issue : In the openCropActivity method set - .withMaxResultSize to (1000,1000)

UCrop.of(sourceUri,` destinationUri)
.withMaxResultSize(1000, 1000)
.withAspectRatio(5f, 5f)
 .start(this);

ImranLoneRider avatar Mar 24 '19 05:03 ImranLoneRider

Hi all, I tried all above spoken solutions, still quality issue exits. Kindly let me know if any possible solution we have to maintain same size.

Thanks.

RagulSAP avatar Oct 16 '20 16:10 RagulSAP

Hi all, I tried all above spoken solutions, still quality issue exits. Kindly let me know if any possible solution we have to maintain same size.

Thanks.

uCrop.withMaxResultSize(1000, 1000); options.setCompressionQuality(100); options.setMaxBitmapSize(10000);

use these three lines, this will improve the quality

durejagaurav avatar Aug 25 '21 16:08 durejagaurav