image - 在 flutter 中检查图像大小(kb,mb ...)?

标签 image flutter dart

我知道如何检查图像的宽度和高度:

import 'dart:io';

File image = new File('image.png'); // Or any other way to get a File instance.
var decodedImage = await decodeImageFromList(image.readAsBytesSync());
print(decodedImage.width);
print(decodedImage.height)
但是我想检查图像大小,例如 100kb、200kb 或类似的大小,有什么办法吗,请帮助我。

最佳答案

使用 lengthInBytes .

final bytes = image.readAsBytesSync().lengthInBytes;
final kb = bytes / 1024;
final mb = kb / 1024;
如果您想 async-await , 用
final bytes = (await image.readAsBytes()).lengthInBytes;

关于image - 在 flutter 中检查图像大小(kb,mb ...)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64571052/

相关文章:

flutter - 无需大量 "if-then"逻辑即可实现图标-文本映射

sockets - 如何响应 Dart 上的套接字

http - 接受任何 SSL 证书都会导致我的程序挂起

c# - 如何在C#中将jpg、位图格式的图片转换为矢量格式

javascript - 为 Javascript 游戏显示卡片图像的最有效方式

php - 在 PHP 中裁剪图像

android - Flutter iOS 应用程序 - 在 TestFlight 中测试应用程序升级

java - 如何在JPanel中设置背景图片

具有自定义形状的 Flutter 按钮 - (三角形)

functional-programming - Dart:映射列表(list.map)