Dhaval2404 / ImagePicker

📸Image Picker for Android, Pick an image from Gallery or Capture a new image with Camera

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing image formats (PNG to JPG) itself

saqibsoftwares opened this issue · comments

Hi,
The library is changing selected PNG image into JPG image itself when .maxResultSize and .compress functions are used with the Companion.

ImagePicker.Companion.with(this).galleryOnly().maxResultSize(Globals.MAX_IMAGE_WIDTH, Globals.MAX_IMAGE_HEIGHT).compress(Globals.MAX_IMAGE_SIZE_KB).start

Is there any way to keep the original format?

@saqibsoftwares Have you tried in v1.7.3? I think the issue is resolved in this version. Please let me know if the issue still persists.

implementation 'com.github.dhaval2404:imagepicker:1.7.3'

Thank you for replying.
Unfortunately the problem is still. I updated to 1.7.3 and tried it again same results. I cleaned my android studio project then built it again still the same problem.

Here is the file name which I'm giving it as source file:
/storage/emulated/0/Download/face-png-vladimir-putin-face-png-image-1645.png

Here is the new file name it returning after compressing/resizing:
/storage/emulated/0/DCIM/Camera/IMG_20200801_231355718.jpg

I have even tried to add mime type (.galleryMimeTypes(new String[]{"image/png"})) with the request but same results.

Here is the full code I'm using

ImagePicker.Companion.with(PeopleEditorActivity.this).compress(Globals.MAX_IMAGE_SIZE_KB).maxResultSize(Globals.MAX_IMAGE_WIDTH, Globals.MAX_IMAGE_HEIGHT).galleryMimeTypes(new String[]{"image/png"}).galleryOnly().start(new Function2<Integer, Intent, Unit>()
                {
                    @Override
                    public Unit invoke(Integer integer, Intent intent)
                    {
                        if (intent.getData() != null)
                        {
                            final String path = ImagePicker.Companion.getFilePath(intent);
                            addSingleImage(position, path);
                        }
                        return null;
                    }
                });

I tried to dig into the library to provide you more information,

inside CompressionProvider class there is a method called startCompression
private fun startCompression(file: File): File? { used to compress the provided PNG image file. It called multiple times until we got our desired compress size. Inside this method on the following line
newFile = applyCompression(file, attempt)
When the attempt is zero the file in our provided PNG file but when the attempt is one (or greater) the file changed and becomes a JPG file with random file name and JPG extension and the same file returned to our calling activity.

May be the above information could help you to find the problem. Use the large size PNG image 3 or 4 MB in size and try to compress is with very small size like 500KB to reproduce the problem. Can you please also give us max file size selection limit so we can restrict user to select large files.

@saqibsoftwares Thank you so much for the detailed information. I will get back to you shortly. I really appreciate you putting your effort behind improving this lib. This will be helpful to lots of Users.
Thank you again!

Don't thank me. What I did is nothing as compared to what you have done for all of us by creating this amazing library. Just one more request that please add Max File Size option just like you have added mime type option. This should disable all the images in selection list those are greater than allowed file size.

@saqibsoftwares I have fixed the issue now. You can verify the changes in v1.7.4. Thank you!

Thanks a lot. Confirmed. Issue has been resolved in v1.7.4.

@Dhaval2404 I'm still facing image format issue in version 2.1