日期:2014-05-19  浏览次数:20921 次

根据URL生成网页缩略图
给定一个URL(网址),要求得到该网页的一个缩略图.
请问如何实现啊??
或者给一个思路也行,
谢谢!

------解决方案--------------------
http://www.websnapr.com/ 
先申请一个key 
然后在你要用的缩略图时,将下面的size,key和url换成你的就好。 
http://images.websnapr.com/?size=size&key=key&url=url 

size=T (92x70 pixels) 
size=S (202x152 pixels) 
size=M (400x300 pixels) 
size=L (640x480 pixels) 


例如<img src="http://images.websnapr.com/?size=M&key=key&url=www.baidu.com"> 

左面应用的话,通过winsock之类的远程取回图片即可。 

------ 
其实直接使用http://images.websnapr.com/?size=t&url=www.163.com就可以了,图片会被打上一行字。
------解决方案--------------------
请问下你要js端截屏的还是java段啊 ?
js的话就需要个ocx控件来调用截屏
java的话倒是有个

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import chrriis.dj.nativeswing.swtimpl.NativeComponent;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserAdapter;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserEvent;

public class Main extends JPanel {
/**

*/
private static final long serialVersionUID = 1L;

// 行分隔符
final static public String LS = System.getProperty("line.separator", "\n");

// 文件分割符
final static public String FS = System.getProperty("file.separator", "\\");

//以javascript脚本获得网页全屏后大小
final static StringBuffer jsDimension;

static {
jsDimension = new StringBuffer();
jsDimension.append("var width = 0;").append(LS);
jsDimension.append("var height = 0;").append(LS);
jsDimension.append("if(document.documentElement) {").append(LS);
jsDimension.append(
" width = Math.max(width, document.documentElement.scrollWidth);")
.append(LS);
jsDimension.append(
" height = Math.max(height, document.documentElement.scrollHeight);")
.append(LS);
jsDimension.append("}").append(LS);
jsDimension.append("if(self.innerWidth) {").append(LS);
jsDimension.append(" width = Math.max(width, self.innerWidth);")
.append(LS);
jsDimension.append(" height = Math.max(height, self.innerHeight);")
.append(LS);
jsDimension.append("}").append(LS);
jsDimension.append("if(document.body.scrollWidth) {").append(LS);
jsDimension.append(
" width = Math.max(width, document.body.scrollWidth);")
.append(LS);
jsDimension.append(
" height = Math.max(height, document.body.scrollHeight);")
.append(LS);
jsDimension.append("}").append(LS);
jsDimension.append("return width + ':' + height;");
}

public Main(final String url, final int maxWidth, final int maxHeight) {
super(new BorderLayout());
JPanel webBrowserPanel = new JPanel(new BorderLayout());
final String fileName = System.currentTimeMillis() + ".jpg";
final JWebBrowser webBrowser = new JWebBrowser(null);
webBrowser.setBarsVisible(false);
webBrowser.navigate(url);
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);