please help : how do I get from an RGB color to a ColorKey?

shukri

Member
Joined
Mar 1, 2004
Messages
6
I need to set a transparent color on a bitmap displayed in DirectX 9 (using C#). That part is easy - and it works for black. Simply create a ColorKey object and set both its ColorSpaceHighValue and ColorSpaceLowValue to 0, and all black on the bitmap becomes transparent. Problem is, how do I set a different color to be transparent? How do I for example specify an RGB value for my ColorKey? What exactly do High and Low value mean anyway? Each is an int - RGB values have three int values, not two.

I dont want to use pure black (RGB (0,0,0)) as my transparent color, but rather nearly pure black (RGB (1,1,1)).

Ive tried

myColorKey.ColorSpaceHighValue = Color.FromArgb(
1,
1,
1
).ToArgb();

myColorKey.ColorSpaceLowValue = Color.FromArgb(
1,
1,
1
).ToArgb();

, but this doesnt work. It seems the only color I can use for transparency is black, and all the online examples/tuts Ive encountered use black as well. Seems to be a typical case of everyone copying from the same source example without trying to actually use the code in real-life.

Can anyone help me PLEASE :-)

Thanks

Shukri
 
This is what I use:

key.ColorSpaceHighValue = int.Parse("FF00FF", NumberStyles.HexNumber);
key.ColorSpaceLowValue = int.Parse("FF00FF", NumberStyles.HexNumber);


This particular examples uses Magenta, which is FF00FF, which is also (255,0,255) for transparency. Ive also used other colors under this method, and it works just like youd expect.

Im not completely sure how to define your value in three seperate 0-255 numbers, but if you know (or can learn) how to convert them to hex, those lines should work for you.

Im not sure exactly what the high and low values are for -- Ive always set them to the same thing and it works perfectly for me.

-Hiro_Antagonist
 
Back
Top