AssetImage 和 ExactAssetImage 有什么区别?

iDe*_*ode 5 flutter

我无法理解AssetImage和之间的区别ExactAssetImage。我可以用

Image(
  image: AssetImage(chocolateImage),
)
Run Code Online (Sandbox Code Playgroud)

或者

Image(
  image: ExactAssetImage(chocolateImage),
)
Run Code Online (Sandbox Code Playgroud)

没有性能或内存差异。唯一的优势ExactAssetImage就是scale房产,但这就是全部吗?如果是的话,那还需要什么AssetImage

enc*_*bos 3

这与您在资源列表中提供的具有不同像素密度的图像有关。

我的意思是当你提供这样的图像时:

icons/heart.png 
icons/1.5x/heart.png 
icons/2.0x/heart.png
Run Code Online (Sandbox Code Playgroud)

如果您使用AssetImage,flutter 将根据设备密度像素在 3 个图像之间进行选择。

在设备像素比为 1.0 的设备上,选择的图像将为 heart.png;在设备像素比为 1.3 的设备上,选择的图像将为 1.5x/heart.png。


如果您使用ExactAssetImage,则可以手动选择比例,执行以下操作:

Image(image: ExactAssetImage("your-asset",scale: 2)),
Run Code Online (Sandbox Code Playgroud)