Aerus
Aerus

Reputation: 4380

GWT opacity of image on canvas

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?

Upvotes: 0

Views: 271

Answers (1)

Baz
Baz

Reputation: 36884

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

Upvotes: 1

Related Questions