I looked into this thread but the methods are deprecated and for me doesn't even work. I tried to do something similiar but failed. My sample code:
public interface Resources extends ClientBundle{
@Source("images/castle.png")
ImageResource castleIcon();
And the class that draws the image:
private void drawImage() {
Resources res = GWT.create(Resources.class);
final Image icon = new Image(res.castleIcon().getSafeUri());
icon.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
icon.setPixelSize(100, 80);
}
});
context.drawImage(createImageElement(icon), x - 65, y - 20);
}
private ImageElement createImageElement(Image image) {
return ImageElement.as(image.getElement());
}
I've tried this approach but it fails to render transparent background