Results 1 to 8 of 8
  1. #1
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default How to create off screen BufferedImage capture

    suppose I wanted to create a BufferedImage, except it i would have to capture it on a window that is minimized. How should I do this? Thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    If the window is not showing, then the Robot class is no use.
    An idea: Create a BufferedImage, get its graphics context and call the window's paint method to have it draw itself on your image.

  3. #3
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    If the window is not showing, then the Robot class is no use.
    An idea: Create a BufferedImage, get its graphics context and call the window's paint method to have it draw itself on your image.
    Thanks for your reply,
    How should I do this? Can you give me an example?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Sorry, I don't have any examples.

  5. #5
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    any ideas? I'm stumped.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Have you tried what I suggested earlier:
    Create a BufferedImage,
    get its graphics context
    call the window's paint method with the graphics to have it draw itself on your image.

    Searching on this forum for new BufferedImage( found code examples for the first two steps.

    The third step would be:
    windowRef.paint(g); // for AWT
    or
    windowRef.paintComponent(g); // for swing

    Now your buffered image contains what the window would have painted on the screen.
    I don't know about the window's contained components. Try it and see what you get
    Last edited by Norm; 09-05-2010 at 05:21 PM.

  7. #7
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Okay, This is how i paint a component:
    Java Code:
     public static BufferedImage paintComponent(Graphics g) {
    		 
    		  BufferedImage grid = null;
    		        x.paintComponents(g);       // paint background
    		        Graphics2D g2 = (Graphics2D)g; // we need a Graphics2D context
    		            int w = x.getWidth();
    		            int h = x.getHeight();
                        grid = (BufferedImage)(x.createImage(w,h));
    
    
             return grid;
    		  }
    and here is how i call this method:

    Java Code:
     Graphics g = x.getGraphics();
    		BufferedImage picImageArea = paintComponent(g);
    		try {
    
    			ImageIO.write(picImageArea, "png", new File("test.png"));
    		} catch (IOException e1) {
    			e1.printStackTrace();
    		}
    When I see the saved image, I see nothing but white. "x" refers to another window that is opened. What is happening?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Java Code:
    public static BufferedImage paintComponent(Graphics g) {
    That is not the signature for the component's paintComponent method.
    Are you intending to override the component's method?

    Java Code:
        x.paintComponents(g);       // paint background
    What is x???

    What is happening?
    I don't understand your code.
    How does it relate to what I suggested?

    The three steps:
    BufferedImage bi = new BufferedImage( ....);
    Graphics g = bi.getGraphics();

    windowRef.paint(g); // have the window paint itself on our image

Similar Threads

  1. How to do a screen capture of content on web page/join 2 images
    By raabie in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-27-2010, 01:02 PM
  2. DVB-T capture
    By krato in forum Advanced Java
    Replies: 0
    Last Post: 08-03-2010, 11:46 PM
  3. Replies: 0
    Last Post: 12-29-2009, 03:10 PM
  4. Need Help on Remote Host Screen Capture
    By krishnaraoveera1294 in forum AWT / Swing
    Replies: 4
    Last Post: 03-13-2009, 10:56 PM
  5. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 05:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •