Want to read from disk and resize an image in Flutter? You can read image from the disk using the image.file constructor. For more features you can use the Image library.
1 2 3 4 5 6 7 8 9 10 11 12 13 | import 'dart:io' as Io; import 'package:image/image.dart'; void main() { // Read a jpeg image from file. Image image = decodeImage(new Io.File('test.jpg').readAsBytesSync()); // Resize the image to a 120x? thumbnail (maintaining the aspect ratio). Image thumbnail = copyResize(image, width: 120); // Save the thumbnail as a PNG. new Io.File('out/thumbnail-test.png') ..writeAsBytesSync(encodePng(thumbnail)); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.