drawImage method

  1. @override
void drawImage(
  1. PCanvasImage image,
  2. num x,
  3. num y
)
override

Draw an image at (x,y) using the original dimension of the image.

Implementation

@override
void drawImage(PCanvasImage image, num x, num y) {
  checkImageLoaded(image);

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

  var clip = _clip;
  if (clip != null) {
    var imgW = image.width;
    var imgH = image.height;

    var box = PRectangle(x, y, imgW, imgH);
    var r = clip.intersection(box);
    if (r.isZeroDimension) return;

    if (r.width != imgW || r.height != imgH) {
      drawImageArea(image, 0, 0, imgW, imgH, x, y, imgW, imgH);
      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: srcImg.width,
      dstH: srcImg.height,
    );
  } else {
    throw ArgumentError("Can't handle image type: $image");
  }
}