Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Screenshot wont draw to picture?

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Screenshot wont draw to picture?

    I have a screenshot program I made, and for some reason it "draws" to the screen. It really does that thing that Windows likes to do(and I hate it) when it freezes up and you can see random crap like the edge of your window that isn't there anymore.
    The only problem is, it does this, and takes a screenshot when I look away from the program.
    Here is my code:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import javax.swing.JFrame;
     
    public class GuiStart extends JFrame {
     
    	private static final long serialVersionUID = -621866894461974337L;
    	public static BufferedImage remoteDisplayImage;
     
    	public GuiStart() {
     
    		Thread updateThread = new Thread(new UpdateScreen());
    		updateThread.start();
    	}
     
    	@Override
    	public void paint(Graphics g) {
    		Image img = remoteDisplayImage;
    		g.drawImage(img, 0, 0, this);
    	}
    }
     
    class UpdateScreen implements Runnable {
     
    	public void run() {
    		while (true) {
    			try {
    				Toolkit toolkit = Toolkit.getDefaultToolkit();
    				Dimension screenSize = toolkit.getScreenSize();
    				Rectangle rectangle = new Rectangle(0, 0, (int)screenSize.getWidth(), (int)screenSize.getHeight());
    				Robot robot = new Robot();
    				BufferedImage shot = robot.createScreenCapture(rectangle);
     
    				GuiStart.remoteDisplayImage = shot;
    			} catch(Exception ex) { ex.printStackTrace(); }
    		}
    	}
    }
    BTW, sorry for the name of the topic, I meant "Screenshot wont draw to form" :L


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    660
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Screenshot wont draw to picture?

    Any time in which the frame needs to be refreshed, such as resizing or moving the frame out of the bounds of your monitor, the paint(Graphics) method will be called.
    So I imagine what you're seeing is the new screenshot being painted, but containing the old screenshot (as it was on your screen when the screen capture occurred) resulting in some weird self contained image.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. Converting a picture made up of 0s and 1s into a colored picture??
    By Kranti1992 in forum Java Theory & Questions
    Replies: 10
    Last Post: November 21st, 2011, 05:25 PM
  2. Change the random draw line here for a mouseListener draw
    By Panda23 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2011, 02:29 AM
  3. Showing a picture in a GUI
    By joachim89 in forum AWT / Java Swing
    Replies: 1
    Last Post: February 15th, 2010, 01:42 PM
  4. My Clear Info button is not working with Screenshot
    By drkossa in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 15th, 2010, 07:06 AM
  5. Need help with a Picture!
    By Scout in forum Java Theory & Questions
    Replies: 1
    Last Post: October 12th, 2009, 05:33 PM

Tags for this Thread