drawImageArea method

  1. @override
void drawImageArea(
  1. PCanvasImage image,
  2. int srcX,
  3. int srcY,
  4. int srcWidth,
  5. int srcHeight,
  6. num dstX,
  7. num dstY,
  8. num dstWidth,
  9. num dstHeight,
)
override

Draw an image part (srcX,srcY , srcWidth x srcHeight) to a destiny area (dstX,dstY , dstWidth x dstHeight).

Implementation

@override
void drawImageArea(PCanvasImage image, int srcX, int srcY, int srcWidth,
    int srcHeight, num dstX, num dstY, num dstWidth, num dstHeight) {
  checkImageLoaded(image);

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

  var clip = _clip;
  if (clip != null) {
    var box = PRectangle(dstX, dstY, dstWidth, dstHeight);
    var r = clip.intersection(box);
    if (r.isZeroDimension) return;

    if (r.width != dstWidth || r.height != dstHeight) {
      var imgW = image.width;
      var imgH = image.height;

      var rW = (imgW / dstWidth);
      var rH = (imgH / dstHeight);

      srcX = ((r.x - dstX) * rW).toInt();
      srcY = ((r.y - dstY) * rH).toInt();
      srcWidth = (r.width * rW).toInt();
      srcHeight = (r.height * rH).toInt();

      dstX = r.x.toInt();
      dstY = r.y.toInt();
      dstWidth = r.width.toInt();
      dstHeight = r.height.toInt();
    }
  }

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