如何在Flutter / Dart中读取(从磁盘)和调整图像大小

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,120);
 
  // Save the thumbnail as a PNG.
  new Io.File('out/thumbnail-test.png')
        ..writeAsBytesSync(encodePng(thumbnail));
}

 

posted @ 2021-06-21 08:59  技术研究与问题解决  阅读(965)  评论(0)    收藏  举报