Płótno HTML Metoda putImageData()
Przykład
Poniższy kod kopiuje dane pikseli dla określonego prostokąta na kanwę za pomocą getImageData(), a następnie umieszcza dane obrazu z powrotem na kanwie za pomocą 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);
}
Obsługa przeglądarki
Liczby w tabeli określają pierwszą wersję przeglądarki, która w pełni obsługuje tę metodę.
Method | |||||
---|---|---|---|---|---|
putImageData() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Definicja i użycie
Metoda putImageData() umieszcza dane obrazu (z określonego obiektu ImageData) z powrotem na kanwie.
Wskazówka: Przeczytaj o metodzie getImageData() , która kopiuje dane pikseli dla określonego prostokąta na kanwę.
Wskazówka: Przeczytaj o metodzie createImageData() , która tworzy nowy, pusty obiekt ImageData.
Składnia JavaScript
Składnia JavaScript: | kontekst .putImageData( imgData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight ); |
---|
Wartości parametrów
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 |
❮Płótno obiektu