Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drawing in 8 bit and 24 bit modes

6 views
Skip to first unread message

Farooque Khan

unread,
Jun 24, 2009, 1:22:24 AM6/24/09
to

Hi,

We are porting a legacy windows GUI application from 8 bit (application only
works in 256 color mode) to 24 bit (trying to make it support both modes).
We have managed to get the graphics to show on both modes but with some
problems. The drawn graphics appear properly in 8 bit mode, but are shifted
to right and clipped in 24 bit mode. We have managed to simulate the
behaviour in a sample application (code below), which is almost same as the
legacy application code. The sample code just draws a simple rectangle which
we then save to a bitmap to observe the behaviour (saving to a bitmap file
is not relevant to the issue here). We then run the application in 8 bit
mode (256 colors) and 24/32 bit colors and save the bitmap. The 8 bit bitmap
(drawn rectangle) appears OK, but the 24 bit one is shifted to the right and
clipped. Can anybody suggest what is going wrong here? Any tips, hints etc.
would be appreciated. Thanks,


<CODE BEGIN>

CDC *pDC = GetDC();

CDC memDC;
CBitmap memBM;

CRect clRect;

GetClientRect(&clRect);


memDC.CreateCompatibleDC(pDC);
memBM.CreateCompatibleBitmap(pDC, clRect.Width(), clRect.Height());

memDC.SelectObject(&memBM);

memDC.BitBlt(0, 0, clRect.Width(), clRect.Height(), NULL, 0, 0, WHITENESS);

CPalette *pPlt = pDC->GetCurrentPalette();

memDC.SelectPalette(pPlt, FALSE);
memDC.RealizePalette();


// Creating recangle 400 x 400 logical unit
CRect rect;

rect.left = 50;
rect.top = 100;

rect.right = rect.left + 400;
rect.bottom = rect.top + 400;

memDC.SetMapMode(MM_ISOTROPIC);

memDC.SetWindowOrg(864, 865);
memDC.SetViewportExt(1282, 1283);

memDC.SetWindowOrg(-432, -432);
memDC.SetViewportOrg(50, 50); // PS: Not a good idea to play with viewport
and window org at the same time
memDC.Rectangle(&rect);

// Saving bitmap into file, not relevant to the issue
CDIBSectionLite db;
db.SetDIBitmap(memBM, pPlt);

db.SetDither(FALSE);
db.Save("out.bmp");


<CODE END>

-Farooque


Chris Hill

unread,
Jun 24, 2009, 8:25:30 PM6/24/09
to

What does db.SetDIBitmap(memBM, pPlt) do and how do you know that the
saving isn't the problem? I don't see anything else in the code you
posted that might explain the problem. memBM seems to be selected
into memDC at the time it is passed to SetDIBitmap, is that
acceptable? Have you tried drawing to the screen instead of a bitmap
or copying the bitmap to the screen instead of saving it?

Chris

0 new messages