ASingerMustDie
Programmer
Hi Everyone ,
(Incidentally, I also posted this plea in a Microsoft Newsgroup, I hope that doesn't annoy anyone? )
I am having trouble understanding why the following method (invoked when I click the corresponding button in a dialog) is not drawing an image to the screen.
void CMyTestDlg::OnDrawButton()
{
// Array representing a 640 * 480 24-bit bitmap
unsigned char displayImage[640 * 480 * 3];
// Client area of a frame (static) control
CDC *clientDC;
clientDC = GetDlgItem(IDC_DRAW_FRAME)->GetDC();
int pix;
for (int y = 0; y < 480; y++)
{
for (int x = 0; x < 640; x++)
{
// For now I am just setting each RGB (or BGR) component to 50
// until the program works that is
// (Obviously memset would be faster and better otherwise)
pix = (y * 640 * 3) + (x * 3);
displayImage[pix] = 50; // Green
displayImage[pix+1] = 50; // Blue
displayImage[pix+2] = 50; // Red
}
}
BITMAP bm;
bm.bmType = 0;
bm.bmWidth = 640;
bm.bmHeight = 480;
bm.bmWidthBytes = 640 * 3;
bm.bmPlanes = 1;
bm.bmBitsPixel = 24;
bm.bmBits = displayImage;
CBitmap displayBitmap;
displayBitmap.CreateBitmapIndirect(&bm);
// displayBitmap should now be a dark grey 24-bit bitmap
// Create memory based device context and select in the bitmap
CDC MemDC;
MemDC.CreateCompatibleDC(clientDC);
MemDC.SelectObject(&displayBitmap);
// BitBlt the bitmap to the control device context
clientDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &MemDC, 0, 0, SRCCOPY);
}
And what I see is nothing...nothing happens. I have noticed that if I change bm.bmBitsPixel to 16, an image is copied to the control, but it is obviously distorted.
What is the problem?
Thanks much indeed in advance,
Tracy
(Incidentally, I also posted this plea in a Microsoft Newsgroup, I hope that doesn't annoy anyone? )
I am having trouble understanding why the following method (invoked when I click the corresponding button in a dialog) is not drawing an image to the screen.
void CMyTestDlg::OnDrawButton()
{
// Array representing a 640 * 480 24-bit bitmap
unsigned char displayImage[640 * 480 * 3];
// Client area of a frame (static) control
CDC *clientDC;
clientDC = GetDlgItem(IDC_DRAW_FRAME)->GetDC();
int pix;
for (int y = 0; y < 480; y++)
{
for (int x = 0; x < 640; x++)
{
// For now I am just setting each RGB (or BGR) component to 50
// until the program works that is
// (Obviously memset would be faster and better otherwise)
pix = (y * 640 * 3) + (x * 3);
displayImage[pix] = 50; // Green
displayImage[pix+1] = 50; // Blue
displayImage[pix+2] = 50; // Red
}
}
BITMAP bm;
bm.bmType = 0;
bm.bmWidth = 640;
bm.bmHeight = 480;
bm.bmWidthBytes = 640 * 3;
bm.bmPlanes = 1;
bm.bmBitsPixel = 24;
bm.bmBits = displayImage;
CBitmap displayBitmap;
displayBitmap.CreateBitmapIndirect(&bm);
// displayBitmap should now be a dark grey 24-bit bitmap
// Create memory based device context and select in the bitmap
CDC MemDC;
MemDC.CreateCompatibleDC(clientDC);
MemDC.SelectObject(&displayBitmap);
// BitBlt the bitmap to the control device context
clientDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &MemDC, 0, 0, SRCCOPY);
}
And what I see is nothing...nothing happens. I have noticed that if I change bm.bmBitsPixel to 16, an image is copied to the control, but it is obviously distorted.
What is the problem?
Thanks much indeed in advance,
Tracy