Home > database >  Is it possible to have Flutter image_picker return two of the same image but with different quality?
Is it possible to have Flutter image_picker return two of the same image but with different quality?

Time:05-16

Flutter image_picker package allows one to select the quality of an image very easily and the re-sizing works really quickly:

XFile? pickedImage = await _picker.pickImage(
                                      imageQuality: 80,
                                      source: ImageSource.gallery);

I am looking for a best way to have the picked image be in a original size and smaller size for a thumbnail.

I have tried packages like image_compression_flutter but at least for web it seemed very slow, whereas as image_picker works very fast regardless of the quality setting (0-100).

Is there a good way to to use image_picker to do this?

The goal would be that the user picks one image but then there would be two files - pickedImage (imageQuality:80) and pickedImageThumb (imageQuality:10). Right now of course this code below does not work as it creates two instances of picking an image. Is there a way to do this without having the user pick the same image twice?

XFile? pickedImage = await _picker.pickImage(
                                      imageQuality: 80,
                                      source: ImageSource.gallery);

 XFile? pickedImageThumb = await _picker.pickImage(
                                      imageQuality: 10,
                                      source: ImageSource.gallery);

If this does not work, is it possible to somehow use the same method image_picker uses in the background to do the compression as a stand alone function that would take pickedImage and resize it?

What is the main reason image_picker can do the compression so quickly compared to other packages and methods?

CodePudding user response:

While I was trying to pick image from Flutter web I had some difficulties. Firstly,there was no XFile type, so picking from web required to use packages. However, those packages had were too slow at compressing images. I opened a new issue here, then I found workaround, which is commented there. I'm still waiting for the soulution of the issue to be able to compress web image.

If you want to resize an image you should sacrifice web support. But if you want web support you should resize the image on your server.

CodePudding user response:

I think there is not a way to return same image with different qualities because of this i advice you that get picked image using image_picker and then resize the same image with different quality . You can use this library (flutter_native_image: ^0.0.6 1) to resize image

  • Related