drawImageScaled method

  1. @override
void drawImageScaled(
  1. PCanvasImage image,
  2. num x,
  3. num y,
  4. num width,
  5. num height,
)
override

Draw an image at (x,y) scaling it to the dimension width x height.

Implementation

@override
void drawImageScaled(
    PCanvasImage image, num x, num y, num width, num height) {
  checkImageLoaded(image);

  x = transform.x(x);
  y = transform.y(y);

  x = canvasX(x);
  y = canvasY(y);
  width = canvasX(width);
  height = canvasY(height);

  final imageWidth = image.width;
  final imageHeight = image.height;

  if (image is _PCanvasImageElement) {
    if (width == imageWidth && height == imageHeight) {
      _ctx.drawImage(image.imageElement, x, y);
    } else {
      _ctx.drawImageScaled(image.imageElement, x, y, width, height);
    }
  } else {
    throw ArgumentError("Can't handle image type: $image");
  }
}