HTML-canvas putImageData() Methode
Voorbeeld
De onderstaande code kopieert de pixelgegevens voor een opgegeven rechthoek op het canvas met getImageData(), en plaatst de afbeeldingsgegevens vervolgens terug op het canvas met 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);
}
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de methode volledig ondersteunt.
Method | |||||
---|---|---|---|---|---|
putImageData() | Yes | 9.0 | Yes | Yes | Yes |
Definitie en gebruik
De methode putImageData() plaatst de afbeeldingsgegevens (van een opgegeven ImageData-object) terug op het canvas.
Tip: Lees over de methode getImageData() waarmee de pixelgegevens voor een opgegeven rechthoek op een canvas worden gekopieerd.
Tip: Lees over de methode createImageData() waarmee een nieuw, leeg ImageData-object wordt gemaakt.
JavaScript-syntaxis
JavaScript-syntaxis: | context .putImageData ( imgData,x,y, dirtyX,dirtyY,dirtyWidth,dirtyHeight ); |
---|
Parameterwaarden
Parameter | Description |
---|---|
imgData | Specifies the ImageData object to put back onto the canvas |
x | The x-coordinate, in pixels, of the upper-left corner of the ImageData object |
y | The y-coordinate, in pixels, of the upper-left corner of the ImageData object |
dirtyX | Optional. The horizontal (x) value, in pixels, where to place the image on the canvas |
dirtyY | Optional. The vertical (y) value, in pixels, where to place the image on the canvas |
dirtyWidth | Optional. The width to use to draw the image on the canvas |
dirtyHeight | Optional. The height to use to draw the image on the canvas |
❮ HTML Canvas-referentie