fromAssetImage static method

Future<BitmapDescriptor> fromAssetImage(
  1. ImageConfiguration configuration,
  2. String assetName, {
  3. AssetBundle? bundle,
  4. String? package,
  5. bool mipmaps = true,
})

从资源图像创建BitmapDescriptor

Flutter中的assert的资产图像按以下方式存储: https://flutter.dev/docs/development/ui/assets and images声明-分辨率感知图像资源 该方法考虑了各种资产解决方案 并根据dpi将图像缩放到正确的分辨率。 将mipmaps1设置为false可加载图像的精确dpi版本,默认情况下,mipmap`为true。

Implementation

static Future<BitmapDescriptor> fromAssetImage(
  ImageConfiguration configuration,
  String assetName, {
  AssetBundle? bundle,
  String? package,
  bool mipmaps = true,
}) async {
  if (!mipmaps && configuration.devicePixelRatio != null) {
    return BitmapDescriptor._(<dynamic>[
      'fromAssetImage',
      assetName,
      configuration.devicePixelRatio,
    ]);
  }
  final AssetImage assetImage =
      AssetImage(assetName, package: package, bundle: bundle);
  final AssetBundleImageKey assetBundleImageKey =
      await assetImage.obtainKey(configuration);
  final Size? size = configuration.size;
  return BitmapDescriptor._(<dynamic>[
    'fromAssetImage',
    assetBundleImageKey.name,
    assetBundleImageKey.scale,
    if (kIsWeb && size != null)
      [
        size.width,
        size.height,
      ],
  ]);
}