怎么获取这个网站的图片的地址? 本帖最后由 shendaowu 于 2015-01-27 16:48:16 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个图片就是一个文件,它在互联网上传递的过程是通过数据流来传播,如果我们直接把数据流字节赋给一个图片的话,也是可以的,就是你给的网站那样,比如数据库中如果直接保存图片或者文件的话,也是一样的。所以只要将图片压缩成存储的字符串就可以了public class Base64ImageAction extends ActionSupport { private final static String galleryName = "gallery"; private static String parent = null; private String encodeString = null; public String getEncodeString() { return encodeString; } public void setEncodeString(String encodeString) { this.encodeString = encodeString; } private String getImageFullPath() { parent = new File(this.getClass().getClassLoader().getResource( File.separator).getPath()).getParent()+File.separator+"flag.jpg"; } public String execute() { ByteArrayOutputStream output = new ByteArrayOutputStream(); try { JimiReader reader = Jimi.createJimiReader(this.getImageFullPath()); Image image = reader.getImage(); Jimi.putImage("image/png", image, output); output.flush(); output.close(); this.encodeString = Base64.encodeBase64String(output.toByteArray()); } catch (IOException e) { e.printStackTrace(); } catch (JimiException e) { e.printStackTrace(); } return SUCCESS; }} 对应的View<html><head><title>Hello,World</title></head><body><img src="data:image/png;base64,${encodeString}" /></body></html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Demo JavaScript PNG Viewer</title> </head><body onload="show(gravatar);"><script src="../Source/Base64.js" type="text/javascript"></script><script src="../Source/Deflate.js" type="text/javascript"></script><script src="../Source/PNG.js" type="text/javascript"></script><script type="text/javascript">var gravatar = 'iVBORw0KGgoAAAANSUhEUgAAA.......数据从略......55CYII=';String.prototype.padRight = function(c, n){ var txt = ''; for(var i=0;i<n-this.length;i++) txt += c; return txt + this;};function show(data){ var png = new PNG(data); var img = document.getElementById('image'), limg = document.getElementById('largeimage'); document.getElementById('nativeimage').src = 'data:image/png;base64,' + data; img.innerHTML = ''; limg.innerHTML = ''; img.style.width = png.width + 'px'; img.style.height = png.height + 'px'; limg.style.width = (png.width * 3) + 'px'; limg.style.width = (png.height * 3) + 'px'; var line; while(line = png.readLine()) { for (var x = 0; x < line.length; x++){ var px = document.createElement('div'), px2 = document.createElement('div'); px.className = px2.className = 'pixel'; px.style.backgroundColor = px2.style.backgroundColor = '#' + line[x].toString(16).padRight('0', 6); img.appendChild(px); limg.appendChild(px2); } }}</script><div id="image"></div><div id="largeimage"></div><img id="nativeimage" /></body></html> jquery.treeview的问题 JS在IE下有效在FF下无效 求大神:版本1.2 jquery-easyUI datagrid 列宽 自适宜问题 search tip 问题 如何取到对应单元格内隐藏文本框的值?? 简单的转到另外一个页面的问题 求以下功能的javascript 分不够再加 客户端设置cookie和服务器端设置cookie有何不同 怎么控制IE的状态栏上进度条 如何用javascript关闭窗口时不弹出确认关闭对话框? ECHARTS如何获取后台数据 求助createRange().text在easyUI标签页面无法获取内容 子页面单独打开可以获得 放在标签里就获取空值
所以只要将图片压缩成存储的字符串就可以了
public class Base64ImageAction extends ActionSupport { private final static String galleryName = "gallery";
private static String parent = null;
private String encodeString = null; public String getEncodeString() {
return encodeString;
} public void setEncodeString(String encodeString) {
this.encodeString = encodeString;
}
private String getImageFullPath() {
parent = new File(this.getClass().getClassLoader().getResource(
File.separator).getPath()).getParent()+File.separator+"flag.jpg";
} public String execute() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
JimiReader reader = Jimi.createJimiReader(this.getImageFullPath());
Image image = reader.getImage();
Jimi.putImage("image/png", image, output);
output.flush();
output.close();
this.encodeString = Base64.encodeBase64String(output.toByteArray());
} catch (IOException e) {
e.printStackTrace();
} catch (JimiException e) {
e.printStackTrace();
}
return SUCCESS;
}
}
<head>
<title>Hello,World</title>
</head>
<body>
<img src="data:image/png;base64,${encodeString}" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo JavaScript PNG Viewer</title>
</head>
<body onload="show(gravatar);">
<script src="../Source/Base64.js" type="text/javascript"></script>
<script src="../Source/Deflate.js" type="text/javascript"></script>
<script src="../Source/PNG.js" type="text/javascript"></script><script type="text/javascript">
var gravatar = 'iVBORw0KGgoAAAANSUhEUgAAA.......数据从略......55CYII=';
String.prototype.padRight = function(c, n){
var txt = '';
for(var i=0;i<n-this.length;i++) txt += c;
return txt + this;
};
function show(data){
var png = new PNG(data);
var img = document.getElementById('image'), limg = document.getElementById('largeimage');
document.getElementById('nativeimage').src = 'data:image/png;base64,' + data;
img.innerHTML = '';
limg.innerHTML = '';
img.style.width = png.width + 'px';
img.style.height = png.height + 'px';
limg.style.width = (png.width * 3) + 'px';
limg.style.width = (png.height * 3) + 'px';
var line;
while(line = png.readLine())
{
for (var x = 0; x < line.length; x++){
var px = document.createElement('div'), px2 = document.createElement('div');
px.className = px2.className = 'pixel';
px.style.backgroundColor = px2.style.backgroundColor = '#' + line[x].toString(16).padRight('0', 6);
img.appendChild(px);
limg.appendChild(px2);
}
}
}
</script>
<div id="image"></div>
<div id="largeimage"></div>
<img id="nativeimage" />
</body>
</html>