Logo
  Sunday, May 20, 2012
Sign-In  |  Sign-Up  |  Contact Us  | Bookmark |  RSS Feed

HTML5 Tutorial FeedBurner

Working with underlying pixels in the HTML5 canvas  
HTML5 developer can gain access to individual pixel in the canvas. The way it is accomplished is via a numerical array. You can modify these pixels and then apply back to canvas.

There are three main functions in HTML5 that can help you accomplish this task

  • context.getImageData(sx, sy, sw, sh)
  • context.putImageData(imagedata, dx, dy)
  • context.createImageData(sw, sh)
Let’s take a closer look at how these functions are utilized by the HTML5 in order to gain access to pixels in the canvas.

context.getImageData(sx, sy, sw, sh) - function has current state of the canvas. It contains a collection of integers. Each object in the array has other properties that are accessible to HTML5 developer: width, heigh and data. Data property has four values each for four color components (red, blue, green and alpha). getImageData function returns information that relates to the region set in the arguments of this function call and limited by this parameters as a result. However, it is easy to update values that are being return as they are 0 to 255 range integer values.

context.putImageData(imagedata, dx, dy) - function is used to update the canvas with the modified pixilation information or image alpha information. putImageData passes modified data in the same format as it retrieved with your modification back to canvas.

context.createImageData(sw, sh) - function creates new image data on the canvas. Data that is being used to create image can be programmatically accessed and modified.

Print Working with underlying pixels in the HTML5 canvas Bookmark Working with underlying pixels in the HTML5 canvas

Related Articles  
Using HTML5 Canvas
HTML5 canvas element creates rectangular area on your HTML5 webpage. It is defaulted at 350 by 150 pixels which can be ...
Using HTML5 Stroke Styles
HTML5 provides with new styling capabilities when it comes to canvas. We can improve the way lines are drawn on canvas ...
HTML5 canvas browser compatibility
HTML5 is not official and mandated version of HTML and not every browser vendor supports it. You need to be aware of ...
Working with HTML5 Paths
The HTML5 Paths are designed to represent any shape that you may want to render. You would use beginPath call to start ...
Drawing Curves in HTML5
HTML5 allows you to draw curves on HTML5 canvas. They way to do it is with the help of paths.
HTML5 Background Patterns
Images can be used throughout web application, but sometimes it is useful to set images as backgrounds.
More