Returns an ImageData object representing the underlying pixel data for the area of the canvas denoted by the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh), in canvas coordinate space units.
Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntaxvar object = object.getImageData(sx, sy, sw, sh);
Parameters sx
The x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.
syThe y-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.
swThe width, in pixels, of the rectangle in relation to the coordinates of the canvas.
shThe height, in pixels, of the rectangle in relation to the coordinates of the canvas.
Return ValueReturns an object of type DOM NodeDOM Node
ICanvasImageData
A CanvasImageData object with pixel information from the canvas within the specified coordinates.
ExamplesThis example draws a solid color filled rectangle, then uses getImageData to retrieve part of the rectangle, and then uses putImageData to place that retrieved data elsewhere on the canvas.
<canvas id="myCanvas" width="300" height="150" style="border:1px solid blue;"></canvas>
<p>. . .</p>
<script>
var can = document.getElementById("myCanvas");
var ctxt = can.getContext("2d");
ctxt.fillStyle = "magenta";
ctxt.fillRect(10, 10, 75, 75);
var imgdata = ctxt.getImageData(10, 10, 30, 30);
ctxt.putImageData(imgdata, 100, 55);
</script>
Notes
If the rectangle contains pixels outside the canvas, they are returned as transparent black. Pixels are returned as non-premultiplied alpha values.
Related specificationsMicrosoft Developer Network: Windows Internet Explorer API reference Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4