THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
Sometimes, We want to read an image from a disk folder and resize it and display the image.
You can use the resized image in flutter widgets to display it
This tutorial explains how to read and resize it.
image
library as a dependency in pubspec.yaml
name: dartapp
description: >-
dart example application.
version: 1.0.0
environment:
sdk: '>=2.10.0 <3.0.0'
dependencies:
image: any
decodeImage
, and convert to a byte in synchronous operation using the readAsBytesSync()
methodcopyResize
and returns the image objectHere is an example program for reading, resize, and outputting image
import 'dart:io' as Io;
import 'package:image/image.dart';
void main() {
// Load a png image.
Image image = decodeImage(new Io.File('myphoto.png').readAsBytesSync());
Image thumbnail = copyResize(image, width: 240);
// save as new file with new resolution
print(new Io.File('output.png')..writeAsBytesSync(encodePng(thumbnail)));
}
🧮 Tags
Recent posts
Nodejs package.json resolutions How to find Operating System username in NodeJS? How to convert Double to Integer or Integer to double in Dart| Flutter By Example Ways to skip test case execution in Gradle project build Learn Gradle | tutorials, and examplesRelated posts