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);

  var clip = _clip;
  if (clip != null) {
    var box = PRectangle(x, y, width, height);
    var r = clip.intersection(box);
    if (r.isZeroDimension) return;

    if (r.width != width || r.height != height) {
      drawImageArea(
          image, 0, 0, image.width, image.height, x, y, width, height);
      return;
    }
  }

  if (image is PCanvasImageMemory) {
    var srcImg = image.image;
    img.compositeImage(
      _bitmap,
      srcImg,
      srcX: 0,
      srcY: 0,
      srcW: srcImg.width,
      srcH: srcImg.height,
      dstX: x.toInt(),
      dstY: y.toInt(),
      dstW: width.toInt(),
      dstH: height.toInt(),
    );
  } else {
    throw ArgumentError("Can't handle image type: $image");
  }
}