Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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)).

 

I've 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 I've 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

Posted

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. I've also used other colors under this method, and it works just like you'd expect.

 

I'm 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.

 

I'm not sure exactly what the high and low values are for -- I've always set them to the same thing and it works perfectly for me.

 

-Hiro_Antagonist

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...