Solved

How to Create DDB with 32bit color DIB ?

Posted on 1998-08-30
4
567 Views
Last Modified: 2013-11-19
Dear experts

I'm using VC++5.0.
I'd like to create a DDB with a 32 bit color DIB.
I tried as followings :

/////
BITMAPINFOHEADER      BmpInfoHdr;

BmpInfoHdr.biSize = sizeof(BITMAPINFOHEADER);
BmpInfoHdr.biWidth = 720;
BmpInfoHdr.biHeight = (-1)*486;
BmpInfoHdr.biPlanes = 1;
BmpInfoHdr.biBitCount = 32;
BmpInfoHdr.biCompression = BI_RGB;
BmpInfoHdr.biSizeImage = 0;
BmpInfoHdr.biXPelsPerMeter = 0;
BmpInfoHdr.biYPelsPerMeter = 0;
BmpInfoHdr.biClrUsed = 0;
BmpInfoHdr.biClrImportant = 0;

CClientDC dc(this);
HDC      hDC = dc.GetSafeHdc();
HBITMAP hBitmap = CreateDIBitmap(hDC,
(LPBITMAPINFOHEADER) &BmpInfoHdr, (LONG) CBM_INIT,
(LPSTR) pFrameDIB, (BITMAPINFO *) &BmpInfoHdr, DIB_RGB_COLORS);
CBitmap* pFrameBmp = new CBitmap;
pFrameBmp->->CreateCompatibleBitmap(&dc, 720, 486);
pFrameBmp->FromHandle(hBitmap);

CDC* pMemDC = new CDC;
pMemDC->CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = pMemDC->SelectObject(pFrameBmp);

dc.SetStretchBltMode(COLORONCOLOR);
dc.BitBlt(0, 0, 720, 486, pMemDC, 0, 0, SRCCOPY);
////////////
Above sample code doesn't display pFrameDIB which is 32 bit color image data. Only black is displayed.

Can anyone let me know how to solve this problem ?
i.e. how to create or set bitmap bits of DDB with 32 bit color image data ?

Best regards
0
Comment
Question by:okg
  • 2
4 Comments
 

Author Comment

by:okg
ID: 1321488
Edited text of question
0
 

Author Comment

by:okg
ID: 1321489
Edited text of question
0
 
LVL 23

Expert Comment

by:chensu
ID: 1321490
The problem of your code is that there is no color palette created. Therefore, the color information is lost if the destination DC is not in 32-bit color mode. Look into the following KB article which I think is useful for you.

PARSEBIT.EXE Directly Accesses the Bits of a DIB Section
http://support.microsoft.com/support/kb/articles/q159/6/49.asp
0
 
LVL 1

Accepted Solution

by:
elf_k earned 200 total points
ID: 1321491
The problem is in your code, some of lines is wrong.
Look at these lines:
// you create new bitmap object
CBitmap* pFrameBmp = new CBitmap;
// you create new bitmap handle 720x486 initialized to black.
pFrameBmp->CreateCompatibleBitmap(&dc, 720, 486);
// error resides here
pFrameBmp->FromHandle(hBitmap);

The problem is in understanding FromHandle() mechanism.
CBitmap::FromHandle() is static function of CBitmap. It creates new CBitmap object based on hBitmap you pass in it. So correct syntax is:
CBitmap* pNewBitmap=CBitmap::FromHandle(hBitmap).

So finally try to replace these three lines with:
CBitmap* pFrameBmp=CBitmap::FromHandle(hBitmap);

.and you will get a badly colored bitmap on the screenm if you have <=256 colors on the screen.

But haftoning, selection of correct palette and decreasing color depth is a subject of another question.
                     Good luck. Elf.



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 78
scoreUp challenge 14 56
noX challenge 17 91
Problem to event 3 75
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now