Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


[java] Any way to get a Pixel's Color of a Graphics object?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Harvester   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 August 2000 - 01:49 AM

What i''m looking for is simply for a way to be able to get the color of a pixel that i choose. i.e. Graphics gfx; ... load some .gif ... Color clr=gfx.GetPixel(x,y); Any ideas? thanks.

Sponsor:

#2 loserkid   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 August 2000 - 06:29 AM

Hello, here is one idea;(not simple but it''s one way) use the pixel grabber class.
Here is how,in the this code segment I''m assuming your using double buffering (if you don''t know what that is goto Gamelan and search for Double Buffering):

    
// pseudo-ish code

Image offScn; // image used for double buffering

int data[]; // used to store the pixel values.

//initialize data[] as

//data = new int[offScn.getWidth(this)*offScn.getHeight(this)];

....
//Here is how to grab the pixels from the screen using the

//offScn image (which represents what''s on the screen):
private void grabPixels() {
PixelGrabber pxgb;
pxgb = new PixelGrabber(offScn,0,0,
offScn.getWidth(this),offScn.getHeigh(this),
data,0,offScn.getWidth(this));
try {
pxgb.grabPixels();
}catch(InterruptedException e) {}
}

public Color getPixel(int x,int y) {
return new Color(data[y*offScn.getWidth(this) + x]);
}

...
//since the double buffer image (offScn) is not the same each
//frame because where painting to it we must grab the pixels

//each time when we want to know what color is at a given

//location


grabPixels();
Color c = getPixel(x,y);



So that''s ONE way of doing it. Keep in mind if you grab the pixels each frame it will slow the program down, so only grab them when you really need to know the color value of a given pixel.

Hope this helped, a little ().


=============================
silly programmer vb is for kids.
============================
www.thejpsystem.com




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS