Solved

How to Create DDB with 32bit color DIB ?

Posted on 1998-08-30
4
573 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 97
Define unique primary key 9 99
iSeries DB2 Query 2 100
How to convert MFC::CString to UTF8 wchar_t* 10 441
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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

736 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