Worst way to take a screenshot of a website using HTMLEditorKIT
To take a screenshot of a website you have to use General idea is given below
f.getContentPane().paint(bi.getGraphics());
ImageIO.write(bi, "png", new File(fs));
Working example of a program
URL u = new URL("http://lenta.ru");
String fs = "lentaru.png";
JFrame f = new JFrame();
JEditorPane jep = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
Container p = f.getContentPane();
jep.setEditorKit(kit);
HTMLDocument doc = (HTMLDocument)jep.getDocument();
doc.putProperty("IgnoreCharsetDirective", true);
kit.read(u.openStream(), doc, 0);
p.add(jep);
f.pack();
System.out.println("Downloaded");
BufferedImage bi = new BufferedImage(
		p.getWidth(), 
		p.getHeight(), 
		BufferedImage.SCALE_DEFAULT
		);
f.getContentPane().paint(bi.getGraphics());
ImageIO.write(bi, "png", new File(fs));
System.out.println(String.format(
		"Saved %sx%s", 
		p.getWidth(), 
		p.getHeight()
		));
System.exit(0);
June 3rd, 2011
Back to main
Moi krug - Yernat Assanov
Advertisement
Documentolog
(C) 2010, kseeker
Email: kseeker@yandex.kz
Используются технологии uCoz