Solved

How to Create DDB with 32bit color DIB ?

Posted on 1998-08-30
4
572 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
how to monitor remote shell execution on linux 9 104
changeXy challenge 13 89
Path of Workbook 3 86
Capture logon name 13 87
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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