2023-06-06 - 获取图片压缩功能
2023-06-05 本文已影响0人
TsingQue
@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(() {});
}
});
});
}