drawImage 方法

  1. @JSName('drawImage')
void drawImage(
  1. CanvasImageSource source,
  2. num destX,
  3. num destY
)

将来自 CanvasImageSource 的图像绘制到当前画布。

source 中的整个图像将从其左上角开始绘制到当前上下文中,位置在点 (destX, destY)。如果图像大于画布允许的大小,图像将被裁剪以适应可用空间。

CanvasElement canvas = new CanvasElement(width: 600, height: 600);
CanvasRenderingContext2D ctx = canvas.context2D;
ImageElement img = document.query('img');

ctx.drawImage(img, 100, 100);

VideoElement video = document.query('video');
ctx.drawImage(video, 0, 0);

CanvasElement otherCanvas = document.query('canvas');
otherCanvas.width = 100;
otherCanvas.height = 100;
ctx.drawImage(otherCanvas, 590, 590); // will get clipped

另请参阅

实现

@JSName('drawImage')
void drawImage(CanvasImageSource source, num destX, num destY) native;