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() | Yes | 9.0 | Yes | Yes | Yes |
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 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-Referenz