Wednesday, April 23, 2014
Sign-In  |  Sign-Up  |  Contact Us  | Bookmark |  RSS Feed

HTML5 Tutorial FeedBurner

How to insert Images into a canvas in HTML5?  
HTML5 allows adding and manipulating images inside a canvas. Images can be modified, stretched and stamped with the help of HTML5 commands. However, there are considerations that you need to take into account while working with images inside a canvas. First, you need to make sure that image is fully loaded before applying any modifications. If you don’t wait, then you canvas will fail to load and error out.

In order to avoid this error we need to load image in the following manner


    function insertImageExample(context) {

    var img = new image();

    img.src = "myimage.jpg"

    img.onload = function() { drawImage(); }



You can see that we call function after image has been loaded into canvas. OnLoad handler takes care of image load and we should not have problems with the canvas and partially loaded images.

In order for image to appear on the canvas as can simply run the following line of code

context.drawImage(img, -1,-10,1,10)

Print How to insert Images into a canvas in HTML5? Bookmark How to insert Images into a canvas in HTML5?

Related Articles  
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 ...
Applying CSS to the HTML5 Canvas
CSS can be applied to the HTML5 canvas and you can do pretty much same things with canvas as with images and other ...
Creating Shadow Effect with HTML5
HTML5 shadows are controlled by several operations available in HTML5 arsenal of operations. The shadow effect can be ...
HTML5 Scaling Canvas
We can always scale object on canvas with the help of context.scale transformation routine. In order to scale an ...
HTML5 Canvas Coordinates
The HTML5 canvas has X-Axis and Y-Axis and is two dimensional. It has starting point in the upper-left corner which ...
HTML5 canvas transformation
Canvas transformation is generally used to set up comprehensive canvas. It can be overkill if you want to create simple ...