toByteData() method allows converting the image
into a byte array. We need to pass the format in the format argument which specifies the format in which the bytes will be returned. It'll return the future that completes with binary data or error.
final pngByteData = await image.toByteData(format: ImageByteFormat.png);
ImageByteFormat
enum contains the following constants.
- png
- rawRgba
- rawUnmodified
- values
For more information about ImageByteFormat
, please have a look at this documentation.
Update : If you want to convert the image file
into bytes. Then use readAsByte() method.
var bytes = await ImagePicker.pickImage(source: ImageSource.gallery).readAsBytes();
For converting image into a file, Check out this answer.