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

  if (image is! _PCanvasImageFlutter) {
    throw ArgumentError(
        "Can't handle image type `${image.runtimeType}`: $image");
  }

  var dstXD = transform.xD(dstX);
  var dstYD = transform.yD(dstY);

  dstXD = canvasXD(dstXD);
  dstYD = canvasYD(dstYD);

  final dstWidthD = canvasXD(dstWidth);
  final dstHeightD = canvasYD(dstHeight);

  final rect1 = Rect.fromLTWH(srcX.toDouble(), srcY.toDouble(),
      srcWidth.toDouble(), srcHeight.toDouble());
  final rect2 = Rect.fromLTWH(dstXD, dstYD, dstWidthD, dstHeightD);

  _widgetPainter.addOp((canvas, size) {
    var paint = Paint();
    canvas.drawImageRect(image.flutterImage, rect1, rect2, paint);
  });
}