DirectDraw, C#, ColorKey

Started by
5 comments, last by Ratman 21 years, 2 months ago
Sorry for the newbie question, but whats the correct thing to do here: ColorKey ck = new ColorKey(); // Create a new colorkey. surfaceAnimation.SetColorKey(ColorKeyFlags.SourceDraw, ck); // Set the colorkey to the bitmap surface. 0 is used for the colorkey, which is what the ColorKey struct is initialized to. I want to change the colorKey to magenta (255,0,255). How do I do that in C#? There were macros to create colors, or I could just use 0xFFFF00FF in C++ / DX8. I cant figure what to do in C# (using unchecked code for 0xFFFF00FF doesnt work). I know you have to set ColorSpaceHighValue and ColorSpaceHighValue, just not sure how to do that. Thanks Ratman
Advertisement
Took me a while to figure out (since the documentation sucks):

ck.ColorSpaceHighValue = ColorTranslator.ToWin32(Color.Magenta)ck.ColorSpaceLowValue = ColorTranslator.ToWin32(Color.Magenta) 


[edited by - FieroAddict on February 8, 2003 11:56:21 AM]
quote:Original post by FieroAddict
Took me a while to figure out (since the documentation sucks):

ck.ColorSpaceHighValue = ColorTranslator.ToWin32(Color.Magenta)ck.ColorSpaceLowValue = ColorTranslator.ToWin32(Color.Magenta)  


[edited by - FieroAddict on February 8, 2003 11:56:21 AM]


To do this with slightly less typing you can do:

ck.ColorSpaceHighValue = Color.Magenta.ToArgb();ck.ColorSpaceLowValue = Color.Magenta.ToArgb(); 


-- Exitus Acta Probat --
Thanks guys!
Argh, ok maybe this doesnt work like I thought. I changed the colorKey like above and I cant get other colors to be "transparents" (not drawn). Yet when I switch the value black pixels are now draw - which they werent before.

Does MDX support color keying like this? Or am I going to have to use alpha channels? It would be really nice if I could just specify the color not to draw. Can anyone help?

Thanks
Ratman
Are you using Drawfast? Both methods work for me.... try a color like White, or Red or something generic. Maybe the Magenta doesn''t correspond to the actually shade of color in your graphics.

back.DrawFast(destRect.X, destRect.Y, mySprite, spriteRect, DrawFastFlags.DoNotWait Or DrawFastFlags.SourceColorKey) 
quote:Original post by FieroAddict
Are you using Drawfast? Both methods work for me.... try a color like White, or Red or something generic. Maybe the Magenta doesn''t correspond to the actually shade of color in your graphics.

back.DrawFast(destRect.X, destRect.Y, mySprite, spriteRect, DrawFastFlags.DoNotWait Or DrawFastFlags.SourceColorKey)  


Yeah Ive tried a few different colors just to be sure, and its not working. Anyone got an example or something?

This topic is closed to new replies.

Advertisement