HTML-Leinwand -putImageData()- Methode
Beispiel
Der folgende Code kopiert die Pixeldaten für ein bestimmtes Rechteck auf der Leinwand mit getImageData() und legt dann die Bilddaten mit putImageData() wieder auf der Leinwand ab:
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);
}
Browser-Unterstützung
Die Zahlen in der Tabelle geben die erste Browserversion an, die das Verfahren vollständig unterstützt.
Method | |||||
---|---|---|---|---|---|
putImageData() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Definition und Verwendung
Die putImageData()-Methode legt die Bilddaten (von einem angegebenen ImageData-Objekt) zurück auf die Leinwand.
Tipp: Lesen Sie mehr über die getImageData()- Methode, die die Pixeldaten für ein bestimmtes Rechteck auf einer Leinwand kopiert.
Tipp: Lesen Sie mehr über die createImageData()- Methode, die ein neues, leeres ImageData-Objekt erstellt.
JavaScript-Syntax
JavaScript-Syntax: | Kontext .putImageData ( imgData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight ); |
---|
Parameterwerte
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 where to place the image on the canvas |
y | The y-coordinate, in pixels, of the upper-left corner of where to place the image on the canvas |
dirtyX | Optional. The x-coordinate, in pixels, of the upper-left corner of where to start drawing the image. Default 0 |
dirtyY | Optional. The y-coordinate, in pixels, of the upper-left corner of where to start drawing the image. Default 0 |
dirtyWidth | Optional. The width to use when drawing the image on the canvas. Default: the width of the extracted image |
dirtyHeight | Optional. The height to use when drawing the image on the canvas. Default: the height of the extracted image |
❮ Canvas-Objekt