问题描述
我有一个SQL数据库,其中包含存储为字节数组的图像。我已经做了一些搜索,并没有找到很多关于如何将这些转换为JSF页面的可用图像类型。任何帮助将不胜感激!
I have a SQL database that contains images stored as a byte array. I have done some searching and have not found much on how to convert these into a useable Image type for a JSF page. Any help would be greatly appreciated!
提前致谢!
(使用JSF 2.0)
(using JSF 2.0)
推荐答案
只需创建一个控制器,输出正确的媒体类型(image / *)
并输出字节。没有必要转换任何东西。如果你想操纵图像,那么你可以使用 ImageIO.read
转换它。但是根据你的问题,听起来你只想显示图像。
Just a create a controller that output the right media type (image/*)
and output the bytes. There is no need to convert anything. If you want to manipulate the images then yes you can convert it using ImageIO.read
. But from your question it sounds like you just want to display the image.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
byte[] bytes = ...
resp.setContentType(mimeType);
OutputStream out = resp.getOutputStream();
out.write(bytes);
}
这篇关于如何将字节数组转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!