2023-06-06 - 获取图片压缩功能
作者:
TsingQue | 来源:发表于
2023-06-05 19:56 被阅读0次
@override
Future thumbnail(String args) async {
final path = args.isNotEmpty ? args : 'test.png';
VRUtils.pathTothumbnail(args).then((value) async {
////判断缩略图是否存在
File txt = File(value);
var dir_bool = await txt.exists(); //返回真假
if (dir_bool) {
return;
}
final cmd = img.Command()
// Decode the image file at the given path
..decodeImageFile(path)
// Resize the image to a width of 64 pixels and a height that maintains the aspect ratio of the original.
..copyResize(width: 64)
// Write the image to a PNG file (determined by the suffix of the file path).
..writeToFile(value);
// On platforms that support Isolates, execute the image commands asynchronously on an isolate thread.
// Otherwise, the commands will be executed synchronously.
await cmd.executeThread().then((value) {
if (mounted) {
setState(() {});
}
});
});
}
本文标题:2023-06-06 - 获取图片压缩功能
本文链接:https://www.haomeiwen.com/subject/oidwedtx.html
网友评论