imagedata = context.createImageData(sw, sh);
- Returns an ImageData object with the given dimensions in CSS pixels (which might map to a different number of actual device pixels exposed by the object itself). All the pixels in the returned object are transparent black.
imagedata = context.createImageData(imagedata);
- Returns an ImageData object with the same dimensions as the argument. All the pixels in the returned object are transparent black.
- Throws a NOT_SUPPORTED_ERR exception if the argument is null.
imagedata = context.getImageData(sx, sy, sw, sh);
- Returns an ImageData object containing the image data for the given rectangle of the canvas.
- Throws a NOT_SUPPORTED_ERR exception if any of the arguments are not finite.
- Throws an INDEX_SIZE_ERR exception if the either of the width or height arguments are zero.
imagedata.width;
imagedata.height;
- Returns a actual dimensions of the data in the ImageData object, in device pixels.
imagedata.data;
- Returns the one-dimensional array containing the data.
context.putImageData(imagedata, dx, dy [, dirtyX, dirtyY, dirtyWidth, dirtyHeight ]);
- Paints the data from the given ImageData object onto the canvas. If a dirty rectangle is provided, only the pixels from that rectangle are painted.
- The globalAlpha and globalCompositeOperation attributes, as well as the shadow attributes, are ignored for the purposes of this method call; pixels in the canvas are replaced wholesale, with no composition, alpha blending, no shadows, etc.
- If the first argument isn't an ImageData object, throws a TYPE_MISMATCH_ERR exception.
- Throws a NOT_SUPPORTED_ERR exception if any of the other arguments are not finite.
Examples
Source (click to expand)
var cnv = document.getElementById('canvas');
var ctx = cnv.getContext('2d');
ctx.width = ctx.width; // Clear the context
// Load an image
var flag = new Image();
flag.src = 'http://blog.burlock.org/files/html5/saflag.png'
// Draw the full image.
ctx.drawImage(flag, 60, 20);
// Copy a part of the canvas using into an imagedata object, then
// draw it back to the canvas.
image = ctx.getImageData(60 + 125, 20 + 25, 50, 50);
ctx.putImageData(image, 60, 140);