I want to write a version of the SAND GAME.
I want to examine the color of every pixel in a Jframe window.
I use something like this.

    Toolkit toolkit =  Toolkit.getDefaultToolkit ();
    Dimension dim = toolkit.getScreenSize();
    int height = dim.height;
    int width = dim.width;


    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();
    BufferedImage bimage = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);



    for (int y = height - 1; y >= 0; y--) {
        for (int x = width - 1; x >= 0; x--) {
           int  rgb   = bimage.getRGB(x, y);
           int  red   = (rgb & 0x00ff0000) >> 16;
           int  green = (rgb & 0x0000ff00) >> 8;
           int  blue  = rgb & 0x000000ff;
           //CONTINUE WITH SOME CODE 
       }}

Is it possible to create an image just of the JFrame window i use and not the hole screen?
I don't want to use the bimage.getSubimage(WIDTH, WIDTH, width, width) method or to constantly calculate the Jframe's window coordinates.
Any ideas ? Thanks for your time.

Have a look at this
http://stackoverflow.com/questions/5853879/java-swing-obtain-image-of-jframe
basically you just create your own buffered image object, then call the JFrame's standard paint method passing your image buffer and hey presto the frame (and its contents) gets painted into your buffer.
ps: you don't need to do that for the whole JFrame, just the content pane should be enough

That's what i need. Works fine. Thanks JamesCherrill

        BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics framegraphic = bimage.getGraphics();
        super.paint(framegraphic);
        framegraphic.dispose();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.