?
Solved

Displaying a bitmap from BITMAP structure. (And accessing BITs)

Posted on 2005-05-08
10
Medium Priority
?
249 Views
Last Modified: 2013-12-03
Dear All,

I am given a task to write a function like following,

BOOL AConverterFunction (BITMAP& srcBitmap, BITMAP& dstBitmap).

As it is seen, I will be given with a structure filled with BITMAP data. What I need is to have a some processing on the data of that BITMAP and to display the BITMAP for debugging purposes. Also I need to access pixel information from the BITMAP structure.

Could anyone plz provide a fraction of code to do this task or provide a know how to do this.

regards,

Janapriya.


0
Comment
Question by:janapriya
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:Mercurius0
ID: 13957698
You should first use this to make a bitmap handle
HBITMAP hBitmap=CreateBitmapIndirect(bitmap);

And then this to display it
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
BitBlt(hDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);

To acces the bit-info use GetDIBits and give bitmap.bmBits with it
0
 

Author Comment

by:janapriya
ID: 13957776
In side OnPaint() I have written a code like this. (I know this is not a good place to read a file.. But to test the code I have done that)

CPaintDC dc(this);

HBITMAP hBitmap = (HBITMAP) LoadImage(NULL, "input.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
BITMAP bitmap;

CBitmap::FromHandle(hBitmap)->GetBitmap(&bitmap);

// I wanted to simulate my situation. (I will be receiving a Filled BITMAP i.e. bitmap)
// Now I will be creating the handle to the bitmap. Please focus on the code below. I know that simply I could have used hBitmap. Since I am getting a bitmap I have to create the handle.

HBITMAP hhBitmap = CreateBitmapIndirect(&bitmap);

HDC hMemDC = CreateCompatibleDC(dc.GetSafeHdc());
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hhBitmap);
BitBlt(dc.GetSafeHdc(), 0, 0, bitmap.bmWidth, bitmap.bmHeight, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);

But this code does not work. I get NULL for hOldBitmap. :(
0
 
LVL 1

Expert Comment

by:Mercurius0
ID: 13957970
Of course hOldBitmap gives NULL if you haven't used hMemDC before. It is just for neat coding and to prevent errors. With SelectObject you put hBitmap in hMemDC and then you blit this hMemDC.

What isn't working exactly? Isn't the bitmap drawn?
 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:janapriya
ID: 13957975
No it is not drawn.  :(
0
 
LVL 1

Expert Comment

by:Mercurius0
ID: 13958024
Are you sure the dc.GetSafeHdc() gives the right hDC?
0
 

Author Comment

by:janapriya
ID: 13958107
I am not sure about it. I assumed that it will provide the correct hDC. Please note that I am not familiar with them very much.
0
 
LVL 1

Accepted Solution

by:
Mercurius0 earned 750 total points
ID: 13958130
Try this line with a global HWND, you are sure to get the right one
hDC = GetDC(hWnd);
0
 

Author Comment

by:janapriya
ID: 16299078
Sorry about the delay, I couldn't recall why I didn't do anything about the points.
project was a success, and answers from Mercurius0 was really helpful. So I will give full credits for him.
0
 

Author Comment

by:janapriya
ID: 16299102
Please note that the answers given by him, helped a lot to gain the right track. My method was written in DLL and I couldn't get the hWnd of a window. Thus, somehow I have managed to find a way to complete it. I couldn't recall the way I have done, since it has been sometime now. Thanks Mercurius0 and EE for all da help
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

807 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