Setpixel question

if i have an HDC and select a monochrome bitmap into it, i should still be able to change the color of the dc by using setpixel, right? but this code doesn't change the colors in dcTrans (it is from a function designed to display a transparent bitmap):

CBitmap* pBOriginal; // pointer to original bitmap, passed into function

COLORREF crOldBack = pDC->SetBkColor(m_crWhite);
COLORREF crOldText = pDC->SetTextColor(m_crBlack);
CDC dcTrans, MaskDC;

// get bitmap information passed into function
BITMAP BOriginalInfo;
BITMAP* pBOriginalInfo = &BOriginalInfo;
pBOriginal->GetBitmap(pBOriginalInfo);
int nWidth = pBOriginalInfo->bmWidth;
int nHeight = pBOriginalInfo->bmHeight;

// Create two memory dcs for the image and the mask
MaskDC.CreateCompatibleDC(pDC);
dcTrans.CreateCompatibleDC(pDC);

// Select the image into the appropriate dc
MaskDC.SelectObject(pBOriginal);

// Create the mask bitmap
CBitmap bitmapTrans;
bitmapTrans.CreateBitmap(nWidth, nHeight, 1, 1, NULL);

// Select the mask bitmap into the appropriate dc
dcTrans.SelectObject(&bitmapTrans);

// Build mask based on transparent colour
MaskDC.SetBkColor(crColour);
dcTrans.BitBlt(0, 0, nWidth, nHeight, &MaskDC, 0, 0, SRCCOPY);

// change to color, doesn't seem to work...
COLORREF cr_black = RGB(0, 0, 0);
COLORREF cr_red = RGB(255, 0, 0);
for(int i = 0; i<nWidth; i++)
{
for(int j = 0; j<nHeight; j++)
{
if(dcTrans.GetPixel(i, j) == cr_black)
{
dcTrans.SetPixel(i, j, cr_red);
}
}
}

pDC->BitBlt(x, y, nWidth, nHeight, &dcTrans, 0, 0, SRCAND); // displays monochrome still

jigen3
[1853 byte] By [jigen3] at [2007-11-18 13:36:32]
# 1 Re: Setpixel question
You're lucky if you see anything with the Monocrhome bitmap. Your CreateBitmap creates a bitmap that is only 1 pixel deep (i.e. black or white). You should create the bitmap using CreateCompatibleBitmap instead, and then I think you'll find that it'll work as you expect.

Good luck.
krmed at 2007-11-11 2:09:40 >
# 2 Re: Setpixel question
thx for the reply. i tried changing the function to CreateCompatibleBitmap(), but the results are still the same... I didn't think that would make a difference because it is not the bitmap i am changing but the dc. or does the kiind of bitmap selected into the dc, not allow me to change its color? (what I am beginning to think)

jigen3
jigen3 at 2007-11-11 2:10:45 >