Code:
void TransBlt(HDC hDC, int x, int y, int width, int height, HDC hDC2, int srcX, int srcY)
{
unsigned char* imageBits;
HDC compDC; // this is for the mask
HDC compDC2; //don't feel like muckin up the HDC passed to this, so make another one
HBITMAP bitmap, oldBitmap, bitmap2, oldBitmap2;
compDC = CreateCompatibleDC(hDC2); //dunno, should this be compatible with hDC instead?
compDC2 = CreateCompatibleDC(hDC2);
BITMAPINFO bi;
memset(&bi, 0, sizeof(bi));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biClrUsed = 0;
bi.bmiHeader.biWidth = width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biPlanes = 1;
bitmap = CreateDIBSection(hDC2, &bi, DIB_RGB_COLORS, (void**)&imageBits, 0, 0);
oldBitmap = (HBITMAP)SelectObject(compDC, bitmap);
bitmap2 = CreateCompatibleBitmap(hDC2, width, height);
oldBitmap2 = (HBITMAP)SelectObject(compDC, bitmap2);
BitBlt(compDC, 0, 0, width, height, hDC2, srcX, srcY, SRCCOPY);
for(int i = 0; i < width * height * 3; i += 3)
{
if(imageBits[i] != 0 || imageBits[i + 1] != 0 || imageBits[i + 2] != 0)
{ //If it's not black, make it white
imageBits[i] = 255;
imageBits[i + 1] = 255;
imageBits[i + 2] = 255;
}
}
BitBlt(hDC, x, y, width, height, compDC, srcX, srcY, SRCINVERT); //blit the mask to the destination
BitBlt(compDC2, 0, 0, width, height, hDC2, srcX, srcY, SRCCOPY); //copy the image to hDC2
BitBlt(compDC2, 0, 0, width, height, compDC, srcX, srcY, SRCINVERT); //blit the mask to hDC2
BitBlt(hDC, x, y, width, height, compDC2, srcX, srcY, SRCINVERT); //blit hDC2 to the destination
SelectObject(compDC, oldBitmap);
SelectObject(compDC2, oldBitmap2);
DeleteObject(bitmap2);
DeleteObject(bitmap);
DeleteDC(compDC);
DeleteDC(compDC2);
}
Could someone point out what's wrong? (well, if everything's wrong, don't because that would take a long time