Lienzo HTML método putImageData()
Ejemplo
El siguiente código copia los datos de píxeles para un rectángulo específico en el lienzo con getImageData(), y luego vuelve a colocar los datos de la imagen en el lienzo con 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);
}
Compatibilidad con navegador
Los números en la tabla especifican la primera versión del navegador que soporta totalmente este método.
Method | |||||
---|---|---|---|---|---|
putImageData() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Definición y uso
El método putImageData() vuelve a colocar los datos de la imagen (de un objeto ImageData especificado) en el lienzo.
Sugerencia: Lea sobre el método getImageData() que copia los datos de píxeles para un rectángulo específico en un lienzo.
Sugerencia: Lea acerca del método createImageData() que crea un nuevo objeto ImageData en blanco.
Sintaxis JavaScript
Sintaxis de JavaScript: | contexto .putImageData( imgData, x, y, sucioX, sucioY, sucioAncho, sucioAltura ); |
---|
Valores paramétricos
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 |
❮ Objeto de lienzo