My current code is blit'ing a small Pbgra32 bitmap onto a larger Pbgra32 bitmap. Works fine. What I would like to do now is make that smaller one partly transparent. To do this, before the blit, I am passing the smaller one to a method that should edit each pixel by leaving the RGB values alone while writing 0x7F to each pixel's A value.
Instead of a 50% transparent image however, I am getting a grey square. What am I doing wrong?
private void MakeTransparent(ref WriteableBitmap bmp)
{
int width = bmp.PixelWidth;
int height = bmp.PixelHeight;
int stride = bmp.BackBufferStride;
int bytesPerPixel = (bmp.Format.BitsPerPixel + 7)/8;
unsafe
{
bmp.Lock();
byte* pImgData = (byte*) bmp.BackBuffer;
int cRowStart = 0;
int cColStart = 0;
for (int row = 0; row < height; row++)
{
cColStart = cRowStart;
for (int col = 0; col < width; col++)
{
byte* bPixel = pImgData + cColStart;
UInt32* iPixel = (UInt32*) bPixel;
bPixel[3] = 0x7F;
cColStart += bytesPerPixel;
}
cRowStart += stride;
}
bmp.Unlock();
}
}