Question

I'm using gwt 2.6.0 and add an image to a canvas like so:

Image image = new Image("url"); 
Element element = image.getElement();

canvas.getContext2d().drawImage(ImageElement.as(element), 0, 0);

However, I want to set the opacity of the image to 0.5.

If I do the following to the element of the original image:

element.getStyle().setOpacity(0.5); 

and add the image to the page (not the canvas) it works fine, but the image on the canvas is still displayed as normal.

How do I set the opacity of an image on a canvas?

Was it helpful?

Solution

Context2d has a method called setGlobalAlpha(double) that should be able to help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top