5

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

st3ffb3
  • 398
  • 3
  • 15

3 Answers3

3

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

An additional explanation:

st3ffb3
  • 398
  • 3
  • 15
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.

Jury Dpling
  • 685
  • 5
  • 10
-1

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

Deepak Ror
  • 2,084
  • 2
  • 20
  • 26