Convert webpage to jpeg image using java

I am creating a Java web application where I want the whole screenshot of a web page if I provide the URL of the web page as input.

The main idea I have is to grab the render component's display buffer. I have no idea how to do this. plz help ..

+5
source share
2 answers

Here is a little trick I used for this application:

reverse demo application http://img580.imageshack.us/img580/742/capturadepantalla201004wd.png A Java application that displays the blog.stackoverflow.com page (click on the image to see a demo video)

, .

, .

  • , URL, .

  • Desktop.open( url ), -.

  • , , java.awt.Robot diks.

- :

 class WebScreenShot {
     public static void main( String [] args ) {
         Desktop.getDesktop().open( args[0] );
         Robot robot = new Robot();
         Image image = robot.createScreenCapture( getScreenResolutionSize() );
         saveToDisk( image );
     }
  }

, , , , craw web .

, html Java.

+3

pure-java, , java HTML4/CSS2, Cobra, Swing . , paint (Graphics g), .

E.g.
Component c = ...; // the browser component
BufferedImage bi = new BufferedImage(c.getWidth(), c.getHeight(), TYPE_INT_RGB)
Graphics2d g = bi.createGraphics();    
c.paint(g);

API- java, JPG.

JPEGImageEncoder encoder = JPEGCodec.createEncoder(new FileOutputStream("screen.jpg"));
enncoder.encode(bi);  // encode the buffered image

Java . , - , , Java .

+3

All Articles