【发布时间】:2023-02-09 17:53:15
【问题描述】:
我正在尝试调整和压缩由图片选择器包裹
但我不知道从哪里获取图像信息(宽度、高度)
我试过图像大小获取器包,但我得到了不受支持的异常
有没有一种简单的方法可以从 XFile 获取宽度和高度?
【问题讨论】:
标签: flutter height width imagepicker
我正在尝试调整和压缩由图片选择器包裹
但我不知道从哪里获取图像信息(宽度、高度)
我试过图像大小获取器包,但我得到了不受支持的异常
有没有一种简单的方法可以从 XFile 获取宽度和高度?
【问题讨论】:
标签: flutter height width imagepicker
你可以试试这个:
XFile? imageFile = await ImagePicker().pickImage(source: ImageSource.camera);
if (imageFile != null) {
final decodedImage = await decodeImageFromList(await imageFile.readAsBytes());
final height = decodedImage.height; // Image height
final width = decodedImage.width; // Image width
}
【讨论】: