0

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.

Edited by nikolaos

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by nikolaos
0

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();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.