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

x
?
Solved

From DIB to Bitmap, FAST

Posted on 2000-03-30
7
Medium Priority
?
908 Views
Last Modified: 2013-11-20
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(NULL);
- select a bitmap object that has the properties we want
      memDC.SelectObject(anOkBitmap);
- create a bitmap object compatible with the current one:
                 bitmap.CreateCompatibleBitmap(&memDC,xsize,ysize);
- 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,value);
                  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.
0
Comment
Question by:gaggio
[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
  • 3
  • 3
7 Comments
 
LVL 8

Expert Comment

by:gelbert
ID: 2670851
See "Bit2Mono.exe Changes Color Bitmaps to Monochrome"
MSDN ID: Q77282
It has sample of convertion from DIB to bitmap
0
 
LVL 23

Expert Comment

by:chensu
ID: 2671543
0
 
LVL 1

Author Comment

by:gaggio
ID: 2673400
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(NULL);
memDC.SelectObject(TheBitmap);
memDC.TextOut(0,0,"TEST");
dc.BitBlt(0,0,dibim.Width(),dibim.Height(),&memDC,0,0,SRCCOPY);


.... 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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Expert Comment

by:chensu
ID: 2673827
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?
0
 
LVL 1

Author Comment

by:gaggio
ID: 2673835
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.
0
 
LVL 23

Accepted Solution

by:
chensu earned 240 total points
ID: 2673870
If you look into the DIBToDDB function, you can see the following line at the beginning of the function.

lpbi = (LPBITMAPINFOHEADER)hDIB;

It means that the function supposes hDIB is a pointer instead of a memory handle. You use GlobalAlloc to allocate a memory object and it returns a handle. In order to use the memory, you use GlobalLock to lock the memory object and it returns a pointer to the first byte of the object's memory block. After using, you use the GlobalUnlock function to unlock it. You may also specify the GMEM_FIXED or GPTR flags when using GlobalAlloc so that it returns a pointer directly.
0
 
LVL 1

Author Comment

by:gaggio
ID: 2673918
Adjusted points from 50 to 60
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
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