tags:

views:

51

answers:

1

Hello, I would like to use an image for background in the canvas element provided by HTML5.

The thing is I don't want the drawing to modify this image, I just want it to be use as a reference or guide for the user.

For example: if I draw a background image on the canvas then I add some lines and random drawings, once I use the erase tool it will erase both the lines I've made and the background image.

How can I prevent this?

Thanx.

+2  A: 

you can use CSS to position the canvas over an <img> element with your background

this is similar to the usual trick to do layered animations: just do a different <canvas> element for each layer and put one on top of the other.

non-drawn pixels of <canvas> are transparent, not white.

Javier
How can I set the canvas background to transparent? So I can place an Image behind it?
Valentina
@Valentina: just don't draw on it! non-drawn pixels are transparent by default
Javier
I think I did not explain myself. I need a background image that I don't want to be modified, I just want the canvas to allow drawing (with the pencil tool and the eraser tool) over it, without modifying the background image. Is possible? How? Can you provide an example?
Valentina
the canvas _is_ transparent. just position it over an `<img>` element and it won't cover it. when you draw on the canvas it will appear on top of the 'background'
Javier
Thank you so much Javier! =)
Valentina
To be obscenely technical, pixels of Canvas could be both transparent _and_ white. Though by default they are transparent black. :D
Simon Sarris