gaggio
asked on
From DIB to Bitmap, FAST
My problem is very clear: I have an HDIB handle to a device independent bitmap.I want to be able to get an HBITMAP handle to a BITMAP object from it.
Until now, my only solution was to do the following:
- create a Memory DC compatible with the display memDC.CreateCompatibleDC(N ULL);
- select a bitmap object that has the properties we want
memDC.SelectObject(anOkBit map);
- create a bitmap object compatible with the current one:
bitmap.CreateCompatibleBit map(&memDC ,xsize,ysi ze);
- select it into memDC
memDC.SelectObject(&bitmap );
- copy PIXEL by PIXEL the DIB object from my DIB class (which has a GetPixel() function):
for(int j=0;j<ysize;j++)
for(int i=0;i<xsize;i++)
{
COLORREF value;
mydibimage.GetPixel(i,j,va lue);
memDC.SetPixel(i,j,value);
}
Well, you can see that it is not very good, especially not FAST.
I'd like to get the the bitmap filled with the DIB bits directly, with some
kind of bitblt function.
SO: how do I get a bitmap from an HDIB?
I need code because I'm late in my project.
Thanks a lot.
Until now, my only solution was to do the following:
- create a Memory DC compatible with the display memDC.CreateCompatibleDC(N
- select a bitmap object that has the properties we want
memDC.SelectObject(anOkBit
- create a bitmap object compatible with the current one:
bitmap.CreateCompatibleBit
- select it into memDC
memDC.SelectObject(&bitmap
- copy PIXEL by PIXEL the DIB object from my DIB class (which has a GetPixel() function):
for(int j=0;j<ysize;j++)
for(int i=0;i<xsize;i++)
{
COLORREF value;
mydibimage.GetPixel(i,j,va
memDC.SetPixel(i,j,value);
}
Well, you can see that it is not very good, especially not FAST.
I'd like to get the the bitmap filled with the DIB bits directly, with some
kind of bitblt function.
SO: how do I get a bitmap from an HDIB?
I need code because I'm late in my project.
Thanks a lot.
Converting DIB to DDB
http://www.codeguru.com/bitmap/dib_to_ddb.shtml
http://www.codeguru.com/bitmap/dib_to_ddb.shtml
ASKER
I'm sorry, but this function does not work for me, Chensu. Or maybe that I don't understand what I should do...
Here's what I tried:
1)HBITMAP hb = DIBToDDB(mydibimage.m_hDib );
CBitmap* TheBitmap = CBitmap::FromHandle(hb);
2)CBitmap b1;
b1.LoadBitmap(IDB_BITMAP1) ;
CBitmap* TheBitmap = &b1;
and then:
CClientDC dc(this); // I want to display on the dialog
CDC memDC;
memDC.CreateCompatibleDC(N ULL);
memDC.SelectObject(TheBitm ap);
memDC.TextOut(0,0,"TEST");
dc.BitBlt(0,0,dibim.Width( ),dibim.He ight(),&me mDC,0,0,SR CCOPY);
.... and in the first case I see nothing, whereas in the second case I see what I should (the bitmap and the text)
What's wrong?
Here's what I tried:
1)HBITMAP hb = DIBToDDB(mydibimage.m_hDib
CBitmap* TheBitmap = CBitmap::FromHandle(hb);
2)CBitmap b1;
b1.LoadBitmap(IDB_BITMAP1)
CBitmap* TheBitmap = &b1;
and then:
CClientDC dc(this); // I want to display on the dialog
CDC memDC;
memDC.CreateCompatibleDC(N
memDC.SelectObject(TheBitm
memDC.TextOut(0,0,"TEST");
dc.BitBlt(0,0,dibim.Width(
.... and in the first case I see nothing, whereas in the second case I see what I should (the bitmap and the text)
What's wrong?
Is hb a valid bitmap handle? Is your mydibimage.m_hDib a memory handle that the DIBToDDB function expects? Have you tried to debug into the DIBToDDB function?
ASKER
My bad.
I had to use a GlobalLock() on the m_hDib of my image class.
If you can you explain me the purpose of GlobalLock(), you'll get 10 extra points.
If you don't want to, just post a comment anyway and you'll get those 50.
I had to use a GlobalLock() on the m_hDib of my image class.
If you can you explain me the purpose of GlobalLock(), you'll get 10 extra points.
If you don't want to, just post a comment anyway and you'll get those 50.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adjusted points from 50 to 60
MSDN ID: Q77282
It has sample of convertion from DIB to bitmap