Click to See Complete Forum and Search --> : If only I could access the pixels
spiffee
March 23rd, 2006, 04:05 PM
I want to make a bitmap, so that I can access the pixels
with a program (using SetPixel is too slow.) I have copied some code from
some threads, but no luck so far. I hope this doesn't sound too stupid, but could I please have some advice on
what I need to do to make an 8 bit bitmap, with a
BITMAPINFO struct?, a name? a handle? a device context?
If I end up with a pointer to it's bits, I can probobaly figure
out how to change it's pixels.
But then I need to blt or setdibits or something to get it in the window,
(which I have a handle to and is sitting peacefully on the screen) Thanks very much.
golanshahar
March 23rd, 2006, 04:19 PM
Look at this articles section it should help you: Bitmaps & Palettes (http://www.codeguru.com/Cpp/G-M/bitmap/)
Cheers
spiffee
March 23rd, 2006, 05:51 PM
Thanks, I already looked at those and copied some code. I'm working on the problem now, but haven't been able to put it all together.
spiffee
March 23rd, 2006, 07:21 PM
Here's an attempt to clarify the depth of my difficulty with some specifics:
(all these questions fit together, and I'm just talking about 8-bit bitmaps)
What's the relationship between a DC, a bitmap, and a window?
What does this do:
BITMAP bmp; (nothing is known about the bitmap)
What does this do:
CreateCompatibleBitmap... (What needs to be filled in? infoheader? RGBQUAD?)
CreateDIBitmap... (?)
Once you have a bitmap, do you need to create a buffer to put its pixels in for access?
And finally how do you copy the pixel bytes that you have manipulated back into a displayable bitmap?
Any help would really help.
spiffee
March 25th, 2006, 10:43 PM
This seems to be about the easiest way to put a C/C++ array on the screen in the form of colored pixels (faster than SetPixel):
HDC dc2;
HBITMAP hbm1;
BYTE bits = new BYTE[160000];
hbm1 = CreateCompatibleBitmap(hDC, 400, 400);
dc2 = CreateCompatibleDC(hDC);
SelectObject(dc2, hbm1);
for (i = 0; i < 160000; ++i)
bits[i] = 0;
SetBitmapBits(hbm1, 160000, bits);
BitBlt(hDC, 0, 0, 400, 400, dc2, 0, 0, SRCCOPY);
hDC is Window DC. Bits[] can be set by the program. Bitmap is 400x400
spiffee
March 25th, 2006, 10:47 PM
Sorry to clutter things up. This is corrected code.
This seems to be about the easiest way to put a C/C++ array on the screen in the form of colored pixels:
HDC dc2;
HBITMAP hbm1;
BYTE *bits = new BYTE[160000];
hbm1 = CreateCompatibleBitmap(hDC, 400, 400);
dc2 = CreateCompatibleDC(hDC);
SelectObject(dc2, hbm1);
for (i = 0; i < 160000; ++i)
bits[i] = 0;
SetBitmapBits(hbm1, 160000, bits);
BitBlt(hDC, 0, 0, 400, 400, dc2, 0, 0, SRCCOPY);
hDC is Window DC. Bits[] can be set by the program. Bitmap is 400x400
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.