HTML canvas putImageData () method
Examples
The following code getImageData () Copy on canvas rectangle designated pixel data, and () the image data back into the canvas by putImageData:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(10,10,50,50);
function copy()
{
var imgData=ctx.getImageData(10,10,50,50);
ctx.putImageData(imgData,10,70);
}
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(10,10,50,50);
function copy()
{
var imgData=ctx.getImageData(10,10,50,50);
ctx.putImageData(imgData,10,70);
}
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support putImageData () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
putImageData () method of the image data (from the specified ImageData objects) back on the canvas.
Tip: See getImageData () method, it can copy the rectangle of pixel data specified on the canvas.
Tip: See createImageData () method, which creates a new blank ImageData object.
JavaScript syntax
JavaScript syntax: | context .putImageData (imgData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight); |
---|
Parameter Value
参数 | 描述 |
---|---|
imgData | 规定要放回画布的 ImageData 对象。 |
x | ImageData 对象左上角的 x 坐标,以像素计。 |
y | ImageData 对象左上角的 y 坐标,以像素计。 |
dirtyX | 可选。水平值(x),以像素计,在画布上放置图像的位置。 |
dirtyY | 可选。垂直值(y),以像素计,在画布上放置图像的位置。 |
dirtyWidth | 可选。在画布上绘制图像所使用的宽度。 |
dirtyHeight | 可选。在画布上绘制图像所使用的高度。 |
HTML canvas Reference Manual