Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Output Image Quality #384

Open
VivekKannaV opened this issue Feb 5, 2018 · 6 comments
Open

Improve Output Image Quality #384

VivekKannaV opened this issue Feb 5, 2018 · 6 comments

Comments

@VivekKannaV
Copy link

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

@musasystem
Copy link

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);

@Legementarion
Copy link
Contributor

@VivekKannaV Hello! Did you solve it?

@Ashu2k
Copy link

Ashu2k commented Jun 30, 2018

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

@ImranLoneRider
Copy link

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);

@RagulSAP
Copy link

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.

@durejagaurav
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants