Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Create DDB with 32bit color DIB ?

Posted on 1998-08-30
4
Medium Priority
?
579 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 600 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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