skip to Main Content

I’m trying to resize and compress the image file (XFile) picked by image_picker package

But I don’t where to get the image information (width, height)

I tried image_size_getter package but I got an unsupported exception

Is there an easy way to get the width and height from XFile?

2

Answers


  1. you can try this:

     XFile? imageFile = await ImagePicker().pickImage(source: ImageSource.camera);
    if (imageFile != null) {
      final decodedImage = await decodeImageFromList(await imageFile.readAsBytes());
    final height = decodedImage.height;  // Image height
    final width = decodedImage.width;  // Image width
    }
    
    Login or Signup to reply.
  2. Using the below code you are able to get different things of Image

    import 'dart:io';
    
    XFile? image = await ImagePicker().pickImage(source: ImageSource.gallery);
    var decodedImage = await decodeImageFromList(image.readAsBytesSync());
    print(decodedImage.width);
    print(decodedImage.height);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search