Canvas image masking / overlapping
In my project i have to implement one different color image on the other same size and pattern image using canvas and images are not in round or rectangle shapes. That all are in waves shape and it will apply on a single main background image for showing multiple graphics on every
Overlapped image should be change in another selected color. My question Is there any way with using canvas from that we can change the image color which is draw by canvas or we need to use different images always and apply with CSS/jQuery.
I read about canvas image masking and overlapping. But cant understand with my images because that are not in square or circle shape then first thing is how i draw multiple wave shapes on a single image. I have no idea about that i searched but fail to search perfect solution.
My need is just draw one wave image on canvas and change its color from on click function and also set an another div with background-image and also more then two canvas will overlapped. Is this possible?
(That means : This functionality is for create or set multiple graphics on a car, for that each graphic image need to set in a canvas and for another graphic need to overlapped on div and first canvas)
You can use context compositing to replace part of an image.
For example, if you have this blue logo already as an image:
Any you want the top part of the logo to be colored purple:
You can use compositing to recolor the top part of the image.
First, use your favorite image editor to crop away any part you don’t want recolored.
What’s left is called an overlay.
This overlay part of the image is what we will programmatically recolor.
This overlay can be programatically recolored to any color.
How the overlay was programatically recolored:
- Draw the overlay on an empty canvas.
- Set the compositing mode to “source-in”.
- The Effect: Only existing pixels are replaced—transparent pixels remain transparent
- Now draw a rectangle of any color the covering the canvas
- (remember, only the existing overlay will be replaced with the new color)
How to complete the logo with the changed overlay color
- Set the compositing mode to “destination-atop”
- The Effect: Only transparent pixels are replaced—existing pixels remain unchanged
- Now draw the original logo
- (remember, the existing colored overlay will not be replaced)
This "destination-atop" compositing effect is sometimes called “drawing under”.
This overlay can even be replace with textures!
Here is code and a Fiddle: http://jsfiddle.net/m1erickson/bfUPr/