Click to See Complete Forum and Search --> : Using color class


colinbell
March 17th, 2008, 07:00 AM
I am trying to call the getRed() method on an image like so: image.getRed(); this is the same way i used getRGB and getWidth etc however this causes a cannot find symbol error. This probably sounds very simple and im sure it is however i do not understand this (brain not working).

ProgramThis
March 17th, 2008, 08:19 AM
You can always just get the RGB and shift the data and pull out the red component:

int rgb = image.getRGB(x, y);
int red = ((rgb >> 16) & 0xff);

You can then manipulate the red componant as desired. I'll leave putting the red back in to see if you can get it. If you get stuck, ask.

dlorde
March 17th, 2008, 08:53 AM
In general, it's better to use the classes provided than to manipulate and convert values 'manually' - there's less room for error and confusion: Color color = new Color(image.getRGB(x, y));
int red = color.getRed();Out of clutter, find simplicity. From discord, find harmony. In the middle of difficulty, lies opportunity...
A. Einstein

colinbell
March 17th, 2008, 10:52 AM
Thats exactly what i needed thank you. Just to make sure i understand what is happening is the value returned the intensity of the red part of the pixel. How do the value relate to the getGreen and getBlue parts.

dlorde
March 17th, 2008, 12:45 PM
See java.awt.Color (http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Color.html).

It is not knowledge, but the act of learning, not possession, but the act of getting there which generates the greatest satisfaction...
F. Gauss