Flutter清理图片缓存以及进制之间转换
图像缓存是在启动时由绘图绑定创建的。createImageCache
方法
- 获取图片缓存
ImageCache get imageData => PaintingBinding.instance.imageCache;
- 获取图片缓存大小
int byteData=imageData .currentSizeBytes
获取到的缓存是byte大小,如果用于显示我们可以根据自己实际情况进行转换
1Byte = 8 Bit
1KB = 1,024 Bytes
1MB = 1,024 KB = 1,048,576 Bytes
1GB = 1,024 MB = 1,048,576 KB = 1,073,741,824 Bytes 1GB = 1,024 MB = 1,048,576 KB = 1,073,741,824 Bytes
1TB = 1,024 GB = 1,048,576 MB = 1,099,511,627,776 Bytes
1PB = 1,024 TB = 1,048,576 GB =1,125,899,906,842,624 Bytes
1EB = 1,024 PB = 1,048,576 TB = 1,152,921,504,606,846,976 Bytes
1ZB = 1,024 EB = 1,180,591,620,717,411,303,424 Bytes
1YB = 1,024 ZB = 1,208,925,819,614,629,174,706,176 Bytes
- 清理缓存
imageData.clear();
- (附带)获取缓存图片数量
int allNum = imageData.currentSize;
- (附带)设置缓存大小
imageData.maximumSizeBytes=50<<20;(按照自己实际情况设置,depthData = 50M)