Search code examples
imageflutterdartpicker

image_picker: compressing is not supported for type (null). Returning the image with original quality


I want to change the image quality for picked image, but I got this error. Does anyone know how to fix this? (I got an image from iOS device.)

image_picker: compressing is not supported for type (null). Returning the image with original quality

Future getImageFromCam() async {
    File image;
    try {
      image = await ImagePicker.pickImage(
          source: ImageSource.camera, imageQuality: 90);
    } on Exception {
      _showDialog(context);
    }
  }

Solution

  • According to source code, compress image only support JPEG
    and according to this discussion https://discussions.apple.com/thread/8319465

    All photos taken with the camera will be JPG, unless you go to Settings/Camera - Formats and choose High Efficiency. But High Efficiency will make the photos HEIF,
    

    So you can check your camera setting with this reference https://www.mactrast.com/2017/10/set-iphones-camera-back-saving-photos-jpeg-ios-11/

    IOS part

    https://github.com/flutter/plugins/blob/master/packages/image_picker/ios/Classes/FLTImagePickerMetaDataUtil.m

    (NSData *)convertImage:(UIImage *)image
                   usingType:(FLTImagePickerMIMEType)type
                     quality:(nullable NSNumber *)quality {
      if (quality && type != FLTImagePickerMIMETypeJPEG) {
        NSLog(@"image_picker: compressing is not supported for type %@. Returning the image with "
              @"original quality",
              [FLTImagePickerMetaDataUtil imageTypeSuffixFromType:type]);
      }
    

    Dart part https://github.com/flutter/plugins/blob/master/packages/image_picker/lib/image_picker.dart

     /// The `imageQuality` argument modifies the quality of the image, ranging from 0-100
      /// where 100 is the original/max quality. If `imageQuality` is null, the image with
      /// the original quality will be returned. Compression is only supportted for certain
      /// image types such as JPEG. If compression is not supported for the image that is picked,
      /// an warning message will be logged.