HTML canvas putImageData() Metoda
Příklad
Níže uvedený kód zkopíruje data pixelů pro zadaný obdélník na plátno pomocí getImageData() a poté vloží data obrázku zpět na plátno 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);
}
Podpora prohlížeče
Čísla v tabulce určují první verzi prohlížeče, která tuto metodu plně podporuje.
Method | |||||
---|---|---|---|---|---|
putImageData() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Definice a použití
Metoda putImageData() vloží obrazová data (ze zadaného objektu ImageData) zpět na plátno.
Tip: Přečtěte si o metodě getImageData() , která kopíruje data obrazových bodů pro určený obdélník na plátno.
Tip: Přečtěte si o metodě createImageData() , která vytvoří nový prázdný objekt ImageData.
Syntaxe JavaScriptu
Syntaxe JavaScriptu: | context .putImageData( imgData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight ); |
---|
Hodnoty parametrů
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 |
❮ Objekt plátna