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:
- https://pub.dev/packages/file_picker allows you to pick files/images etc. and the file type of images is .jpg
- https://pub.dev/packages/multi_image_picker allows you to pick images too, but takes the original file format; e.g. .heic, .jpg, .png
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.
Author by
st3ffb3
Updated on December 21, 2022Comments
-
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 almost 4 yearsHave you tried pub.dev/packages/file_picker and picking PNG/JPG images instead of using image picker?
-
st3ffb3 almost 4 yearsAm I able to pick only from gallery?
-
Mohammad Assad Arshad almost 4 yearsthis pub should allow you to pick from multiple directories.
-
-
st3ffb3 almost 4 yearsI want to prevent picking heic, like I’m telling in the title :/
-
Haroon khan over 2 yearsdoes file converts the heic to jpg or it just skips heic image?
-
st3ffb3 over 2 yearsI didn't try it in the last time, but in my opinion the images get converted
-
Ayrix about 2 yearsunfortunately the multi_image_picker is discontinued. do you have an other alternative where I can pick *.heic with except wechat_asset_picker?