Introduce a few Java frames that store Web pages as pictures

Source: Internet
Author: User

First of all, please. Java is very weak in this piece of image. Java is not difficult to implement Java, the principle is to save the current screen into a diagram, and then get the mouse to pull to the location and then save the captured image to the panel inside, and then generate the picture: The sample code will not show, many online. Below is a few frames that save the page as a picture:

①html2image

This is a lot of speculation online. I say this is a jar package that the original Java code encapsulates. The effect is very poor, the code is not posted on the Internet a lot.

②cobra

If you do not know this, you should have heard of Lobobrowser, the pure Java implementation of the browser, tested under, except to start the slow dying other can also.

This code interception is still good, do not say directly on the code:

Package Htmltoimage;import Java.awt.image.bufferedimage;import Java.awt.image.renderedimage;import java.io.File; Import Javax.imageio.imageio;import javax.swing.jframe;import Javax.swing.jpanel;import javax.swing.SwingUtilities ; Import Org.lobobrowser.html.gui.htmlpanel;import Org.lobobrowser.html.test.simplehtmlrenderercontext;import Org.lobobrowser.html.test.simpleuseragentcontext;public class Cobratest {public static void main (string[] args) throws Exception {JFrame window = new JFrame (); Htmlpanel panel = new Htmlpanel (); Window.getcontentpane (). Add (Panel); window.setsize (+); Window.setvisible ( true), new Simplehtmlrenderercontext (panel, New Simpleuseragentcontext ()). Navigate ("http://jobs.zhaopin.com/ 377931819252715.htm?ssidkey=y&ss=201&ff=03 "); System.out.println ("10"); Thread.Sleep (10000); BufferedImage image = New BufferedImage (Panel.getwidth (), Panel.getheight (), BUFFEREDIMAGE.TYPE_INT_ARGB);//Paint the Editor onto the Imageswingutilities.paintcomponent (image.creategraphics(), Panel,new JPanel (), 0, 0, image.getwidth (), Image.getheight ());//Save the image to Fileimageio.write ((renderedimage) Image, "PNG", New File ("Html.png")); System.out.println ("www");}}

But the framework should have a limit, and CSS3 should not support it.

③cssbox

This is very good. If the site is not deliberately limited, it is perfect ...

Package Htmltoimage;import Java.io.file;import Java.io.fileoutputstream;import org.fit.cssbox.demo.ImageRenderer; public class Cssbox {public static void main (string[] args) throws Exception {Imagerenderer render = new Imagerenderer (); S Ystem.out.println ("Kaishi"); String url = "Http://worldwide.espacenet.com/publicationDetails/originalDocument?" Cc=au&nr=2014200109a1&kc=a1&ft=d&nd=3&date=20140821&db=epodoc&locale=en_ep "; FileOutputStream out = new FileOutputStream (New File ("D:" +file.separator+ "html.png")); Render.renderurl (URL, out, Imagerenderer.type_png); System.out.println ("OK");}}

④java native code

Package Htmltoimage;import Java.awt.image.bufferedimage;import Java.awt.image.renderedimage;import java.io.File; Import Java.net.url;import javax.imageio.imageio;import Javax.swing.jeditorpane;import Javax.swing.JPanel;import javax.swing.swingutilities;/** * principle is to display the Web page on the current AWT or swing and save the content as a picture * there is no way to control the delay.  * @author Zlqiao * */public class Javacoreapi {public static void main (string[] args) throws Exception {//load the webpage Into the Editor//jeditorpane ed = new JEditorPane (New URL ("http://www.google.com")); JEditorPane ed = new JEditorPane (New URL ("http://www.baidu.com")); System.out.println ("10"); Thread.Sleep (10000); Ed.setsize (1000,1000);//create a new imagebufferedimage image = New BufferedImage (Ed.getWidth (), Ed.getheight (), BUFFEREDIMAGE.TYPE_INT_ARGB);//paint the editor onto the Imageswing Utilities.paintcomponent (Image.creategraphics (), Ed, new Jpane                               L (),0, 0, image.getwidth (), Image.getheight ()),//save the image to Fileimageio.write ((renderedimage) image, "PNG", New File (" Html.png ")); System.out.println ("OK");}}








Introduce a few Java frames that store Web pages as pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.