What color from the Color Picker?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

What color from the Color Picker?

Gabriel Landini
Hi,
In the color picker I have 2 arbitrary colors set as fore/background.
If one uses those with an 8 bit image to draw some pixels using the pencil
tool, they appear as a grey tone.
I've looked in the IJ source, and found that the FG color can be obtained
from:

Toolbar.getForegroundColor();

My question is, what color does it correspond to, so one can use it in for
example:

 ip.putPixel(x,y, color)

I guess that this color is mapped to some gray value for 1-channel image
types. But how is that done?

Thanks,

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: What color from the Color Picker?

Wayne Rasband
On Oct 17, 2009, at 10:59 AM, Gabriel Landini wrote:

 > Hi, In the color picker I have 2 arbitrary colors set as
 > fore/background. If one uses those with an 8 bit image to
 > draw some pixels using the pencil tool, they appear as a
 > grey tone. I've looked in the IJ source, and found that the
 > FG color can be obtained from:
 >
 > Toolbar.getForegroundColor();
 >
 > My question is, what color does it correspond to, so one can
 > use it in for example:
 >
 > ip.putPixel(x,y, color)
 >
 >  guess that this color is mapped to some gray value for
 > 1-channel image types. But how is that done?

Use the ImageProcessor.getBestIndex() method to convert a Color into a  
LUT index or 8-bit pixel value.

    color = Toolbar.getForegroundColor();
    value = ip.getBestIndex(color);
    ip.putPixel(x,y, value);

-wayne