createScaledImage function

CanvasImageSource createScaledImage(
  1. CanvasImageSource image,
  2. int width,
  3. int height,
  4. double scale,
)

Creates a new image from image, of width and height, to a scale.

Implementation

CanvasImageSource createScaledImage(
    CanvasImageSource image, int width, int height, double scale) {
  var w2 = (width * scale).toInt();
  var h2 = (height * scale).toInt();

  var canvas = CanvasElement(width: w2, height: h2);
  var context = canvas.getContext('2d') as CanvasRenderingContext2D;

  context.drawImageScaledFromSource(image, 0, 0, width, height, 0, 0, w2, h2);

  return canvas;
}