image method

Future<void> image({
  1. required PImage image,
  2. Offset origin = Offset.zero,
  3. double? width,
  4. double? height,
})

Implementation

Future<void> image({
  required PImage image,
  Offset origin = Offset.zero,
  double? width,
  double? height,
}) async {
  final horizontalScale = width != null ? width / image.width : 1.0;
  final verticalScale = height != null ? height / image.height : 1.0;

  final flutterImage = await image.toFlutterImage();

  _paintingContext.canvas
    ..save()
    ..translate(origin.dx, origin.dy)
    ..scale(horizontalScale, verticalScale)
    ..drawImage(flutterImage, Offset.zero, Paint())
    ..restore();

  _paintingContext.markHasUnappliedCanvasCommands();
}