gpt4 book ai didi

java - 如何在 gwt 中管理 Mysql 图像响应?

转载 作者:行者123 更新时间:2023-11-29 00:56:03 25 4
gpt4 key购买 nike

我遇到了一个问题,我无法在 GWT 中显示我的数据库中的图像,即使我证明并且我可以将图像保存在我的计算机中。这是代码:

        byte[] bytes = new byte[8096];
int len = 0;

while ( (len = in.read( bytes ))> 0 )
{
if(!fichero.exists())
{
out.write( bytes, 0, len );
}
}

out.flush();
out.close();
in.close();
//byte[] bytes = IOUtils.toByteArray(in);

String base64 = Base64Utils.toBase64(bytes);
//base64 = "data:image/png;base64,"+base64;
base64 = "data:image/gif;base64,"+base64;
return base64;

}
else
{
return "http://cracktouch.com/wp-content/uploads/2011/02/Run-Like-Hell-Deluxe.png";
}

此代码在类 GreetingServiceImpl 中。“in”是一个带有正确图像的输入流,因为我可以将图像保存在我的计算机中,但是当我像这样使用字符串 base64 时,我无法在 GWT 中显示它:图片 image = new Image(base64);contenido.add(图片);有什么建议吗?

最佳答案

bytes 数组是固定大小的,比图像数据大 - 所以末尾有一些未使用的 0。

调用 Base64Utils.toBase64(bytes) 将整个数组(包括未使用的数据)转换为字符串。

修剪数组或使用 Base64 实现,您可以在其中指定输入数据的大小。

关于java - 如何在 gwt 中管理 Mysql 图像响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6075867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com