Flutter: Picking images as jpg/png instead of heic on iOS

4,414

Solution 1

Thanks to Mohammad Assad Arshad! It can be solved by pub.dev/packages/file_picker.

An additional explanation:

Solution 2

i select images with filepicker https://pub.dev/packages/file_picker

FilePickerResult result;
try {
  result = await FilePicker.platform.pickFiles(
    type: FileType.custom,
    allowedExtensions: ['jpeg', 'jpg', 'heic', 'pdf'],
  );
} catch (e) {
  print('Exep: ****${e}***');
}

now you can check the extention of the file, use the package path.dart as p and package https://pub.dev/packages/heic_to_jpg to convert image to jpeg

 File file = File(result.files.first.path);
  String fileExtension = p.extension(file.path).replaceAll('.', '');
  if (fileExtension == 'heic') {
    print('convert to jpeg');
    String jpegPath = await HeicToJpg.convert(file.path);
    file = File(jpegPath);
    fileExtension = 'jpeg';
  }

do not forget do the same if you use imagePicker with source camera.

Share:
4,414
st3ffb3
Author by

st3ffb3

Updated on December 21, 2022

Comments

  • st3ffb3
    st3ffb3 over 1 year

    How can I pick images directly as jpg or png on iOS? If this feature isn't available: How can I convert it very fast and don't have to wait a long time?

    Edit: I want to prevent picking .heic because I have to send it to an server, which handles jpg and png and not .heic

    • Mohammad Assad Arshad
      Mohammad Assad Arshad almost 4 years
      Have you tried pub.dev/packages/file_picker and picking PNG/JPG images instead of using image picker?
    • st3ffb3
      st3ffb3 almost 4 years
      Am I able to pick only from gallery?
    • Mohammad Assad Arshad
      Mohammad Assad Arshad almost 4 years
      this pub should allow you to pick from multiple directories.
  • st3ffb3
    st3ffb3 almost 4 years
    I want to prevent picking heic, like I’m telling in the title :/
  • Haroon khan
    Haroon khan over 2 years
    does file converts the heic to jpg or it just skips heic image?
  • st3ffb3
    st3ffb3 over 2 years
    I didn't try it in the last time, but in my opinion the images get converted
  • Ayrix
    Ayrix about 2 years
    unfortunately the multi_image_picker is discontinued. do you have an other alternative where I can pick *.heic with except wechat_asset_picker?