我正在使用Dio lib下载映像,并使用path_provider lib将其存储在临时目录中。如何获取图像,将其调整为手机的高度和宽度,并将其保存在临时目录中?
我尝试使用此Image lib,但它与我在同一dart文件中使用的Image.network(url)冲突,因此我正在寻找替代方法。
resizeWallpaper方法的示例使用了发生冲突的图像库。
Dio dio = Dio();
try {
var dir = await getTemporaryDirectory();
await dio.download(widget.url, "${dir.path}/image.png",
onReceiveProgress: (received, total) {
setState(() {
isDownloading = true;
progressString =
((received / total) * 100).toStringAsFixed(0) + "%";
print(progressString);
if (progressString == "100%") {
//resizeWallpaper("${dir.path}/image.png");
_setWallpaper();
}
});
});
} catch (e) {
}
Future<Null> resizeWallpaper(String path) async {
File wallpaper = File(path);
Image image = decodeImage(File(wallpaper).readAsBytesSync());
Image thumbnail = copyResize(image, width: 120);
}