Home > Archive > VC Language > May 2006 > Black background results
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Black background results
|
|
|
| memdc2.CreateCompatibleDC(pDC);
bmpBuffer2 = (BYTE *) GlobalAlloc (GPTR, bmpX.bmWidth*bmpX.bmHeight);
memset ((BYTE*)bmpBuffer2, 0, sizeof(BYTE*));
for (int x = 0; x < ds.dsBm.bmHeight; x++) {
for (int y = 0; y < ds.dsBm.bmWidth; y+=3) {
if (flags[x*ds.dsBm.bmHeight+y] == true) {
bmpBuffer2[x*ds.dsBm.bmHeight+y] = 255;
bmpBuffer2[x*ds.dsBm.bmHeight+y+1] = 0;
bmpBuffer2[x*ds.dsBm.bmHeight+y+2] = 255;
}
else
{
bmpBuffer2[x*ds.dsBm.bmHeight+y] = 255;
bmpBuffer2[x*ds.dsBm.bmHeight+y+1] = 255;
bmpBuffer2[x*ds.dsBm.bmHeight+y+2] = 0;
}
}
}
//GlobalFree((HGLOBAL)bmpBuffer2);
}
// redefinebitmap.SetBitmapBits(ds.dsBm.bmHeight*ds.dsBm.bmWidth,
bmpBuffer2);
// redefinebitmap.GetBitmap(&bmpY);
redefinebitmap.CreateCompatibleBitmap(pDC, ds.dsBm.bmWidth,
ds.dsBm.bmHeight);
memdc2.SelectObject(redefinebitmap);
pDC->BitBlt (0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, &memdc2,
0, 0, SRCCOPY);
GlobalFree((HGLOBAL)bmpBuffer2);
Please help. Been staring at it for a day...
Thanks
Jack
| |
| Tamas Demjen 2006-05-26, 7:09 pm |
| Jack wrote:
> bmpBuffer2[x*ds.dsBm.bmHeight+y] = 255;
> bmpBuffer2[x*ds.dsBm.bmHeight+y+1] = 0;
> bmpBuffer2[x*ds.dsBm.bmHeight+y+2] = 255;
Assuming x is the column and y is the row, and bits_per_pixel is 24,
it's more like
bmpBuffer2[y * bytes_per_line + x * 3] = 255;
bmpBuffer2[y * bytes_per_line + x * 3 + 1] = 0;
bmpBuffer2[y * bytes_per_line + x * 3 + 2] = 255;
where bytes_per_line = (width * bits_per_pixel + 31) / 32 * 4;
You must also account for the bitmap being upside down, by either using
y = height - 1 - row, or by making increment negative.
And your code could be twice as fast using pointer arithmetics than
arrays. You're basically recaluclating the offset 3 times per pixel,
using 6 multiplications and 8 additions per pixel, when you could just
keep incrementing a pointer (3 additions per pixel).
Tom
|
|
|
|
|