문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top