在Flutter /dart 中,我如何执行以下3个步骤:
- 从磁盘读取图像,
- 读取其原始尺寸(宽度和高度),
- 调整其大小.
注意:我必须能够显示一个常规的Flutter 图像小工具的最终结果.
CLARIFICATION:我不想保存图像,但我确实想在内存中调整它的大小.
在Flutter /dart 中,我如何执行以下3个步骤:
注意:我必须能够显示一个常规的Flutter 图像小工具的最终结果.
CLARIFICATION:我不想保存图像,但我确实想在内存中调整它的大小.
您可以使用image.file构造函数从磁盘读取图像.
要了解更多功能,您可以使用Image library
提供加载、保存和操作功能的DART库 各种不同文件格式的图像.
文档中的样本examples
加载jpeg,调整其大小,并将其另存为png
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));
}