colorkey problem for DirectDraw
I have a 24 bit BMP image with 96x96 tiles, with a background color (which is neither black or white) for transparency.
It is loaded on to a surface of smaller size so as expected the image is shrunk according to the surface size.
But as a result, there was no transparency, somehow the color has changed. But if i load the image with the correct size, it works. Even by loading onto a surface half the image size, it works...
I included an excerpt from my code that I used for converting the color key from RGB to the integer color value.
///
/// Counts the width of bits.
///
private byte countBitWidth( int _i )
{
uint i = (uint)_i;
while((i&1)==0) i>>=1;
byte w=0;
while(i!=0)
{
i >>= 1;
w++;
}
return w;
}
///
/// Converts a Color into a fill value.
///
private uint colorToFill( Color c , DirectDrawSurface7 surface)
{
byte widthR,widthB,widthG;
// compute the bit shift width for color fill
DDPIXELFORMAT pixelFormat = new DDPIXELFORMAT();
surface.GetPixelFormat( ref pixelFormat );
widthR = countBitWidth(pixelFormat.lRBitMask);
widthG = countBitWidth(pixelFormat.lGBitMask);
widthB = countBitWidth(pixelFormat.lBBitMask);
uint x = 0;
x |= ((uint)c.R)>>(8-widthR);
x <<= widthG;
x |= ((uint)c.G)>>(8-widthG);
x <<= widthB;
x |= ((uint)c.B)>>(8-widthB);
return x;
}
Is there anyone who can solve this problem?