GWT的base64形象 [英] gwt base64 image

查看:184
本文介绍了GWT的base64形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从通过JAXB的XML文件中获取一个base64字节[]和我不知道如何转换这回的GWT图像(这基本上是一个底层的HTML IMG,如果我了解,正确)。如何转换成正确的字符串?

I am getting a base64 byte[] from an xml file via jaxb and I am not sure how to convert this back to an gwt image (which is basically an underlying html img if I understood that correctly). How do I convert into the proper string?

我的第一反应是到

public void onSuccess(final byte[] icon) {
img.setUrl("data:image/png;base64,"+icon.toString());

但显然不起作用。
任何帮助AP preciated!

but obviously that does not work. Any help is appreciated!

推荐答案

如果你想使用数据URI (用base64编码) - 尽管IE< = 7不支持它,IE8只允许最多32 KB的 - 你必须为base64-CN code中的图像数据

If you want to use data URIs (with base64 encoding) - although IE <=7 doesn't support it, and IE8 only allows up to 32 kB - you'll have to base64-encode the image data.

有几个Base64编码的连接周围例如codeRS com.google.gwt.user.server.Base64Utils ,您可以在服务器端使用:

There are several Base64 encoders around e.g. com.google.gwt.user.server.Base64Utils, which you can use on the server side:

String base64 = Base64Utils.toBase64(icon);

然后连接$ C $光盘的数据传送到客户端。

Then transfer the encoded data to the client.

如果你绝对要,你也可以使用在客户端的连接codeR,但这需要对Java文件复制到客户端源(如果你要确保你选择的实施允许)

If you absolutely want to, you could also use the encoder on the client side, but that would require to copy the java file to the client source (if you make sure that the implementation you choose allows that).

这篇关于GWT的base64形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆