createCanvasImage method

  1. @override
PCanvasImage createCanvasImage(
  1. Object source, {
  2. int? width,
  3. int? height,
})
override

Creates a PCanvasImage instance compatible to this canvas and its painter.

Implementation

@override
PCanvasImage createCanvasImage(Object source, {int? width, int? height}) {
  var id = ++_imageIdCount;

  if (source is String) {
    var imageElement = HTMLImageElement()
      ..src = source
      ..crossOrigin = 'anonymous';

    if (width != null) {
      imageElement.width = width;
    }

    if (height != null) {
      imageElement.height = height;
    }

    return _PCanvasImageElement('img_$id', imageElement);
  } else {
    throw ArgumentError("Can't handle image source: $source");
  }
}