Java 从字节数组设置 img src
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30129486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set img src from Byte Array
提问by Rodrigo Juarez
I need to set the img src
property from a byte array that I have in a Object.
我需要img src
从对象中的字节数组设置属性。
<img id="profileImage">
<spring:bind path="object.profilePicture">
<input type="file" name="profilePicture" id="profilePicture" path="profilePicture">
</spring:bind>
I need to display that byte array in the img
above the input tag.
我需要在img
上面的输入标签中显示该字节数组。
回答by DonO
Replace the jpg
with the type of image, and [your byte array]
with your byte array
. You need to convert it to base64
if it isn't already.
将 替换jpg
为图像类型,并 [your byte array]
替换为您的byte array
. base64
如果还没有,您需要将其转换为。
<img id="profileImage" src="data:image/jpg;base64, [your byte array]">
回答by Francisco M
In my case the base64 byte array had to be chunked, in the way:
在我的情况下,base64 字节数组必须分块,方式如下:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QCARXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUA
AAABAAAARgEoAAMAAAABAAIAAIdpAAQAAAABAAAATgAAAAAAAABIAAAAAQAAAEgAAAABAAOQAAAH
...
To make this solution works.
为了使这个解决方案有效。
回答by Serj Sagan
I use this site to convert images to the base64
byte array data, it gives me the tags in html
and css
so I just upload and copy/paste.
我使用这个网站将图像转换为base64
字节数组数据,它给了我标签html
,css
所以我只需上传和复制/粘贴。