1

I am attempting to cast an Image to a File in Flutter. Is there a method for this?

1 Answer 1

2

This is how to pick an image as a file

File _image;

Future getImage() async {
     final pickedFile = await picker.getImage(source: ImageSource.gallery);
     setState(() {
       _image = File(pickedFile.path);

     });
   }

Also We can convert this image as Bytestream

var convertedImage;

Future getImage() async {
     final pickedFile = await picker.getImage(source: ImageSource.gallery);
     convertedImage = await pickedFile.readAsBytes();
     convertedImage = await decodeImageFromList(convertedImage);
     setState(() {
       convertedImage = convertedImage;
     });
   }

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.