我知道如何检查图像的宽度和高度:
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/