Future<BitmapData> load(String url, [ BitmapDataLoadOptions bitmapDataLoadOptions ])

Loads a BitmapData from the given url.

Source

static Future<BitmapData> load(String url, [BitmapDataLoadOptions bitmapDataLoadOptions]) async {

  if (bitmapDataLoadOptions == null) {
    bitmapDataLoadOptions = BitmapData.defaultLoadOptions;
  }

  var pixelRatio = 1.0;
  var pixelRatioRegexp = new RegExp(r"@(\d)x");
  var pixelRatioMatch = pixelRatioRegexp.firstMatch(url);
  var maxPixelRatio = bitmapDataLoadOptions.maxPixelRatio;
  var webpAvailable = bitmapDataLoadOptions.webp;
  var corsEnabled = bitmapDataLoadOptions.corsEnabled;

  if (pixelRatioMatch != null) {
    var match = pixelRatioMatch;
    var originPixelRatio = int.parse(match.group(1));
    var devicePixelRatio = env.devicePixelRatio.round();
    var loaderPixelRatio = minInt(devicePixelRatio, maxPixelRatio);
    pixelRatio = loaderPixelRatio / originPixelRatio;
    url = url.replaceRange(match.start, match.end, "@${loaderPixelRatio}x");
  }

  var imageLoader = new ImageLoader(url, webpAvailable, corsEnabled);
  var image = await imageLoader.done;
  return new BitmapData.fromImageElement(image, pixelRatio);
}