Solved

How to Obtain HBITMAP from LPBITMAPINFOHEADER

Posted on 2004-08-23
10
1,198 Views
Last Modified: 2008-03-10
I must be missing something pretty simple here. I have a fully populated LPBITMAPINFOHEADER structure:

LPBITMAPINFOHEADER *ppbi = new LPBITMAPINFOHEADER;
GetVideoFrame(0, 0, ppbi);   // gets first frame of first stream (array begins with zero)

This part works. I now need to pass an HBITMAP to another function that will ultimately StretchBlt() it into a surface.

How do I obtain an HBITMAP from this LPBITMAPINFOHEADER?

THANKS
0
Comment
Question by:PMH4514
  • 4
  • 4
  • 2
10 Comments
 
LVL 13

Assisted Solution

by:SteH
SteH earned 20 total points
ID: 11871805
Did you had a look at
http://www.codeguru.com/bitmap/dib_to_ddb.shtml

You need to create this HBITMAP from the info supplied using LPBITMAPINFOHEADER (CreateDIBitmap or CreateBitmap)
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 30 total points
ID: 11871882
Having a BITMAPINFOHEADER structure doesn't means that it exists a bitmap object, that why you can't find a reference to HBITMAP inside the structure.
You can create a new bitmap object based on BITMAPINFOHEADER by calling CreateDIBBitmap() function:
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_5d4g.asp
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11871892
sorry, simultaneous writting
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 13

Expert Comment

by:SteH
ID: 11871904
Don't worry, that can happen.
0
 

Author Comment

by:PMH4514
ID: 11872501
you both I believe are referring me to the CreateDIBitmap () method?
0
 
LVL 13

Expert Comment

by:SteH
ID: 11872629
It depends on the data you got. Is it a device dependent bitmap? That means is the information of it prepared for display on the screen or was it displayed on the screen already? If yes it is most likely device dependant and you should use CreateBitmap (...). If it is calculated from some other parameters or prepared for writing to disk it is more likely a device independant bitmap and you should use CreateDIBitmap (...).

If it is a capture from a video stream I would guess to be in dependant form whereas an image extracted from a stream should be still an independant bitmap.

And what is the difference now. DIBs are normally 24 bit color, 8bit greyscale or black and white. No lookup table for colors is needed since full information is stored for each pixel. DDBs are reduced in color space to the screen resolution they should be displayed on. Either a color table defines what color corresponds to each pixel value (ie 16 or 256 colors) or only reduced set of colors is available (64k or millions of colors).
0
 

Author Comment

by:PMH4514
ID: 11872918
it's coming from a 24bit AVI stream:

in header:
PGETFRAME m_pVideoPGF[MAX_VIDEO_STREAMS];

in code:
PGETFRAME &pgf = m_pVideoPGF[nStreamNum];
*ppbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, lFrame);

and so I am left with the LPBITMAPINFOHEADER which I need to derive a CBItmap handle from.

I'll go take a look and see what I see with the CreateDIBitmap method.
0
 
LVL 13

Expert Comment

by:SteH
ID: 11872934
For 24 bit the difference should be marginal if there is one.
0
 

Author Comment

by:PMH4514
ID: 11872995
I'm confused about how to get the lpbInit and lpbmi paramaters for CreateDIBitmap() from my LPBITMAPINFOHEADER structure.
0
 

Author Comment

by:PMH4514
ID: 11874989
I figured it out :)

hBMP = ::CreateDIBitmap(hdcScreen, lpbi, CBM_INIT, pData, m_pVideoFormats[nStreamNum], DIB_PAL_COLORS);

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

813 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