hk_lok_yu
asked on
using colorkey in C# and Directx 9.0
how to use the ColorKey and also what are the tricks about using the Colorkey ,what i should be careful about the Draw method...or other SurfaceDescription or SurfaceCaps or anything else...
Thank You Very Much!!!
Thank You Very Much!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am using DirectX 9.0 and DirectDraw. Under this scenario, if you specify a ColorKey, the color (or colors) described by the colorkey are treated as FULLY TRANSPARENT. The following code creates an off-screen DirectDraw surface ready to "Blit" into a BackBuffer which is then FLIPed onto the primary buffer.
SurfaceCaps caps = new SurfaceCaps();
caps.OffScreenPlain = true;
SurfaceDescription desc = new SurfaceDescription(caps);
ColorKey clrKey = new ColorKey();
clrKey.ColorSpaceLowValue = 0;
clrKey.ColorSpaceHighValue
desc.SourceDraw = clrKey;
surface = new Surface(bitmap,desc,dev);
Notice I set the color key to Low & High to 0. This are INT32 values. A setting of 0/0 means that the PURE BLACK color in the bitmap will be treated as FULLY TRANSPARENT when you blit it onto the destination surface as follows:
dstSurface.DrawFast(
dstX, dstY,
this.surface,
srcRectangle,
DrawFastFlags.Wait | DrawFastFlags.SourceColorK
The SourceColorKey flag specifies that the color key of the SOURCE surface (desc.SourceDraw value) be treated as the transparent color. Other combinations are valid.
The question I have been unable to answer is: How do I set the color key to a different color than black!
I tried
clrKey.ColorSpaceValueLow =
clrKey.ColorSpaceValueHigh
But it didn't work.