Skip to content

image_picker resize image #17227

Closed
Closed

Description

@vagrantrobbie

Is it possible at the moment to resize an image without "locking up" the Flutter app UI?

I am using the image_picker plugin to pick an image from the device's Photo Gallery and image.dart lib https://pub.dartlang.org/packages/image to resize the chosen image to a more manageable resolution and then upload it to Firebase Cloud Storage. While the image decoded and then encoded the Flutter UI locks up. Could a chosen image size be generated if passed to .getImage()?

Activity

  1. zoechi commented on May 14, 2018

    @zoechi
    Contributor

    You can try https://docs.flutter.io/flutter/foundation/compute.html
    You need to copy the result back to the UI thread to upload to Cloud Storage because as far as I know currently only the UI thread is allowed to access platform channels.

  2. vagrantrobbie commented on May 14, 2018

    @vagrantrobbie
    Author

    EDIT: Potentially this is a Stack Overflow response

    Thanks for the response.

    I have this working now! After resizing the image, I write the bytes back to a temporary file, upload it and then delete the temp. It works well most of the time but I am having the odd device crash (iPhone 5s). Is there a good way to debug this?

    Some times this error is thrown on the resize
    [VERBOSE-2:dart_isolate.cc(713)] Isolate (149972410) 'main.dart:_spawn()' exited with an error
    [VERBOSE-2:dart_error.cc(16)] isolate terminated by Isolate.kill

    Is there a maximum of isolates that can be called at once? Do we need to clean them up?

  3. urbanmania commented on Jul 11, 2018

    @urbanmania

    @vagrantrobbie did you ever get this sorted? I'm having similar problems, odd crashes on older devices.

  4. zoechi commented on Jul 11, 2018

    @zoechi
    Contributor

    @vagrantrobbie I don't think there is a hard limit of isolates, but they take up memory and if you run to many at once you can easily run out of memory.

    @urbanmania please add details about the problems.

  5. urbanmania commented on Jul 11, 2018

    @urbanmania

    ok, thanks. I'm looking at this plugin now to get around this problem https://github.com/btastic/flutter_native_image

  6. vagrantrobbie commented on Jul 11, 2018

    @vagrantrobbie
    Author

    @urbanmania I never really fixed the problem but with a clean run on the app and no hot reloading the error was infrequent enough for me to be happy.

    ImagePicker plugin has a maxWidth property which I utilised
    ImagePicker.pickImage(source: ImageSource.gallery, maxWidth: 800.0); and this was enough to fix my problem. FlutterNativeImage looks handy

  7. urbanmania commented on Jul 11, 2018

    @urbanmania

    ah, had forgotten about that, I should look into that, thanks for reminding me of that.

  8. zoechi commented on Jul 12, 2018

    @zoechi
    Contributor

    @vagrantrobbie do you think there is still something the Flutter team needs to do?
    The ImagePicker issue you mentioned should better be reported in a new issue.

  9. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 12, 2018
  10. vagrantrobbie commented on Jul 13, 2018

    @vagrantrobbie
    Author

    @zoechi sorry for the late reply. I consider this closed. Thanks for following!

  11. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 13, 2018
  12. zoechi commented on Jul 13, 2018

    @zoechi
    Contributor

    @vagrantrobbie thanks for the status update!

  13. hyochan commented on Sep 24, 2018

    @hyochan

    @zoechi @vagrantrobbie I think this isn't enough since we need to generate the thumbnail for every image in general. Therefore maxWidth property is not enough. I've played around with flutter-native-image for this currently but I think ImagePicker should support this feature itself.

  14. zoechi commented on Sep 24, 2018

    @zoechi
    Contributor

    @dooboolab I think it's better to create a new issue.

  15. github-actions commented on Sep 2, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions