【问题标题】:Resizing images in GWT and drawing them on canvas在 GWT 中调整图像大小并在画布上绘制它们
【发布时间】:2012-07-03 08:38:19
【问题描述】:

我查看了this thread,但这些方法已被弃用,对我来说甚至不起作用。我试图做类似的事情但失败了。我的示例代码:

public interface Resources extends ClientBundle{
    @Source("images/castle.png")
    ImageResource castleIcon();

以及绘制图像的类:

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());
}

我试过this approach,但它无法呈现透明背景

【问题讨论】:

    标签: image gwt


    【解决方案1】:

    透明度应该适用于画布上的 PNG。你确定你的图像真的是透明的吗?也许您的 PNG 在某种程度上与画布实现不兼容。尝试使用具有 alpha 透明度的适当 24 位 PNG...

    【讨论】:

    • 当我使用不同的方法时它是透明的。我感觉 getDataImage 不知何故失去了透明度
    猜你喜欢
    • 2020-05-08
    • 2014-07-24
    • 2017-04-22
    • 1970-01-01
    • 2017-06-02
    • 2013-05-26
    • 1970-01-01
    • 2012-08-27
    • 2013-10-06
    相关资源
    最近更新 更多