网页中二进制图片预览


大概的思路:
1 获取图片流
2 读取流字节
3 将字节编码成base64encoding字符
4 构造图片地址"data:image/jpeg;base64," + 编码好的字符

java代码实例:
String url = "http://img1.gtimg.com/finance/pics/hv1/117/56/564/36688497.jpg";		
InputStream is = new URL(url).openStream();
byte[] buffer = new byte[is.available()];
is.read(buffer);
String src = "data:image/jpeg;base64," + new BASE64Encoder().encode(buffer);
System.out.println(src);


html代码实例:
<img src="上面代码输出的src内容"/>

你可能感兴趣的:(java,html)