BGNG
New member
For whatever reason, I cannot get DIB Sections to work in C++ no matter what I try to do. So... help! What I want to do is the simplest thing possible, it's just that I don't know how to do it and all Google ever gives me is VB tutorials and... not much else.
I want to use a DIB Section in my program which defines a 24-bit RGB image with any desired width and height which I can directly modify using a char pointer. I want to be able to access each pixel with X and Y index and modify the color values from there. I also want to be able to give any desired device context to the program and have it be able to transfer the image to it, such that it can be done with BitBlt.
So basically, I want to do something like the following:
If someone can actually make a wrapper that has code EXACTLY like that, it would be great. Otherwise, whatever help that can be provided will be appreciated.
I want to use a DIB Section in my program which defines a 24-bit RGB image with any desired width and height which I can directly modify using a char pointer. I want to be able to access each pixel with X and Y index and modify the color values from there. I also want to be able to give any desired device context to the program and have it be able to transfer the image to it, such that it can be done with BitBlt.
So basically, I want to do something like the following:
Code:
// Create the DIB Section
char* DIBPixel;
HDC PicMan = MakeDIBSection(Width, Height, DIBPixel);
// Make the pixel (X, Y) magenta
int PixelOffset = (Y - 1) * Width + (X - 1) * 3;
DIBPixel[PixelOffset + 0] = 255; // Blue value
DIBPixel[PixelOffset + 1] = 0; // Green value
DIBPixel[PixelOffset + 2] = 255; // Red value
// Transfer the image to another DC, in this case a window
BitBlt(wndDC, 0, 0, Width, Height, PicMan, 0, 0, SRCCOPY);
// Clean up the resources used to make the DIB Section
UnmakeDIBSection(PicMan, DIBPixel);