drawImageScaledFromSource 方法

  1. @JSName('drawImage')
void drawImageScaledFromSource(
  1. CanvasImageSource source,
  2. num sourceX,
  3. num sourceY,
  4. num sourceWidth,
  5. num sourceHeight,
  6. num destX,
  7. num destY,
  8. num destWidth,
  9. num destHeight
)

将图像从 CanvasImageSource 绘制到本画布的某个区域。

图像是位于源点 (sourceX, sourceY) 的 sourceWidth 宽和 sourceHeight 高的区域。图像将被绘制到当前上下文中,其左上角位于 destX, destY,并按比例缩放至 destWidth 宽和 destHeight 高。

如果图像比画布允许的大小大,图像将被裁剪以适应可用空间。

VideoElement video = document.query('video');
video.width = 100;
video.height = 100;
// Take the middle 20x20 pixels from the video and stretch them.
ctx.drawImageScaledFromSource(video, 40, 40, 20, 20, 50, 50, 100, 100);

// Draw the top 100x20 pixels from the otherCanvas to this one.
CanvasElement otherCanvas = document.query('canvas');
ctx.drawImageScaledFromSource(otherCanvas, 0, 0, 100, 20, 0, 0, 100, 20);

另请参阅

实现

@JSName('drawImage')
void drawImageScaledFromSource(
    CanvasImageSource source,
    num sourceX,
    num sourceY,
    num sourceWidth,
    num sourceHeight,
    num destX,
    num destY,
    num destWidth,
    num destHeight) native;