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

3

7

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

Aeneous answered 4/6, 2020 at 8:54 Comment(3)
Have you tried pub.dev/packages/file_picker and picking PNG/JPG images instead of using image picker?Osteoblast
Am I able to pick only from gallery?Aeneous
this pub should allow you to pick from multiple directories.Osteoblast
A
3

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

An additional explanation:

Aeneous answered 8/6, 2020 at 10:13 Comment(4)
does file converts the heic to jpg or it just skips heic image?Outright
I didn't try it in the last time, but in my opinion the images get convertedAeneous
unfortunately the multi_image_picker is discontinued. do you have an other alternative where I can pick *.heic with except wechat_asset_picker?Cauca
@Cauca Can use ImagePicker flutter library, they have multiple images pickers now pub.dev/packages/image_picker/versionsMahican
L
3

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.

Ludwigshafen answered 21/4, 2021 at 8:32 Comment(0)
H
-1

you can use multi_image_picker 4.6.7 to pick image in iOS for HEIC images.

Hughey answered 4/6, 2020 at 9:2 Comment(1)
I want to prevent picking heic, like I’m telling in the title :/Aeneous

© 2022 - 2024 — McMap. All rights reserved.