ADC Home > Reference Library > Technical Q&As > Carbon > Graphics & Imaging >

Not Recommended Documentclose button

Important: The information in this document is Not Recommended and should not be used for new development.

Current information on this Reference Library topic can be found here:

Converting RGB Colors to a Palette Index


Q: How can I convert an RGB color into an index to a palette created by my application? Color2Index converts the RGB color to an index to the current device's color table, but that's not what I want.

A: There's no single call that will give you a palette match to an RGB color. You'll have to do this: call Color2Index to get the closest match to your RGB request; call Index2Color to get the device's indexed color from your match; search the palette yourself to find the color match (according to RGB value); and call Color2Index to verify that you have the color you're looking for.

Alternatively, you can create an off-screen GWorld, call Palette2CTab to convert your palette to a color table, and call UpdateGWorld to insert your new color table in your off-screen GWorld. Then, to find the index of an RGB color, make your GWorld the active device and call Color2Index.

[Sep 15 1995]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.