0

我在服务器端生成一个 base64 图像源,然后通过异步调用将其检索到 GWT 客户端。不幸的是,回调结束后图像未显示(一切正常),但在第二次回调后显示。在创建 Image 对象后,我尝试立即捕获 onLoad 事件,但这并不好。

谢谢!

编辑 1

经过一番调查,这是一个尺寸问题,我的意思是,base64 在那里并且图像标签被正确创建,但是宽度和高度都设置为 0。

编辑 2

这就是我在网站中放置图像的方式:

import net.customware.gwt.dispatch.server.Dispatch
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;

dispatch.execute(action, new AsyncCallback<GenerateImageResult> () {
    @Override
    public void onFailure(Throwable caught) {};
    @Override
    public void onSuccess(GetCarpetasResult result) {
        String base64 = result.getBase64();
        Image image = new Image(base64);
        RootPanel.get().add(image);
    }
});
4

2 回答 2

0

您是否尝试将 onLoadHandler 添加到图像对象?像这样的东西:

image.addLoadHandler(new LoadHandler () {
    @Override
    public void onLoad(LoadEvent event) {
        image.setUrl(base64);
    }
});
于 2013-05-22T01:21:55.417 回答
0

我已经能够使用以下方法成功显示(在 google-chome 中)base64 图像数据:

    String base64= "data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAABMLAAATCwAAAAAAAAAAAAAAAAAAbGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf8AAAAAAAAAAGxsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/AAAAAAAAAABsbG3/bGxt/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsbG3/bGxt/wAAAAAAAAAAbGxt/2xsbf8AAAAAbGxt/2xsbf9sbG3/bGxt/2xsbf9sbG3/bGxt/2xsbf8AAAAAbGxt/2xsbf8AAAAAAAAAAGxsbf9sbG3/AAAAAGxsbf9sbG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AA+MP///+H////DwAA/g8AAA==";
    Image image = new Image(base64);
    RootPanel.get().add(image);

检查这些事情:

  • 您的 base64 数据是否以 开头data:${mime};base64,
  • mime真的在描述解码的base64图像格式吗?
于 2013-05-06T21:09:26.587 回答