dart - 在 Dart 中上传时如何压缩/减小图像大小?

标签 dart flutter

如何在 Dart 中上传时压缩/减小图像大小?我正在尝试上传一张 5MB 的图片,但我想在上传时减小它的大小。我正在使用 Dart 和 Flutter。

最佳答案

有一个image manipulation package on pub .它甚至包括一个示例,说明您究竟想做什么。

import 'dart:io' as Io;
import 'package:image/image.dart';
void main() {
  // Read an image from file (webp in this case).
  // decodeImage will identify the format of the image and use the appropriate
  // decoder.
  Image image = decodeImage(new Io.File('test.webp').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('thumbnail.png')
        ..writeAsBytesSync(encodePng(thumbnail));
}

关于dart - 在 Dart 中上传时如何压缩/减小图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50543060/

相关文章:

google-app-engine - 如何手动删除本地 gcloud Dart DB?

json - Flutter-将JSON文件从url移动到 Assets 文件夹

flutter - 如何在 Flutter 的对话框中访问 Provider 提供者

flutter 错误 : type '_Smi' is not a subtype of type 'double'

flutter - flutter 中的共享首选项在发布时出错

user-interface - 可以在 Flutter 中将文本写入按钮

unit-testing - 如何测试在 Flutter 中使用 package_info 的方法?

android - 如果我的应用程序有 Android native 小部件,苹果会拒绝它吗?

flutter - 无法更改 flutter 中的 Material 图标重量

dart - 导入Dart包