0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

image_pickerで勝手にpngがjpegに変換される件について

Posted at

問題のコード

final picker = ImagePicker();
    final pickedFile = await picker.pickImage(source: ImageSource.gallery);
    if (pickedFile == null) {
      return;
    }

このコードでpathの拡張子を確認するとpngじゃなくてjpgになる。
サイズが大きい画像の場合はpngで保存された画像をpngのまま読み取ってくれるのに、サイズが小さい画像の場合はpngなのにjpgに変換されるというワケワカメ。
調べてみると、iOSの仕様的に変換されることがあるとかどっかに書いてあるので、pickImageは使わないという感じの英語記事がどっかにあった気がするが、URLがどっかいってしまった。とりあえず、下d解決はできた。

解決策

file_pickerを使えばいい

final FilePickerResult? pickedFile = await FilePicker.platform
        .pickFiles(type: FileType.image, withData: true);
Uint8List? pngBytes = pickedFile.files.single.bytes;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?