Question

I'm saving the screenshot of the app to Gallery via -

//screenshot
private void screenshot()
{
    Uri photo = lomography();
    String photopath = photo.getPath();
    try {
        MediaStore.Images.Media.insertImage(getContentResolver(), photopath, "name" , "desc");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

The image stored at the photopath is of high quality:

enter image description here

But when I navigate to Gallery and open the same photo, this is the low JPEG version with several compression artifacts:

enter image description here

Why does the Gallery image a JPEG version when the original file is a PNG? How can I save the high res version to the gallery?

I read here that the trick is in 'Register image with ContentResolver::insert'.

But I'm using getContentResolver.

Was it helpful?

Solution 2

This was the answer. I mean 'this' was the missing part in the code.

Instead of 'MediaStore.Images.Media.insertImage(getContentResolver()'. I should have used MediaStore.Images.Media.insertImage(this.getContentResolver()

Problem solved.

OTHER TIPS

To fix this issue, open the delcaration of the "MediaStore.Images.Media.insertImage" method, copy and paste the code you need into your own class, then where its compressing the image at 50% change it to 100%.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top