janapriya
asked on
Displaying a bitmap from BITMAP structure. (And accessing BITs)
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.
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.
ASKER
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(hBitma p)->GetBit map(&bitma p);
// 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(&bitm ap);
HDC hMemDC = CreateCompatibleDC(dc.GetS afeHdc());
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMem DC, 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. :(
CPaintDC dc(this);
HBITMAP hBitmap = (HBITMAP) LoadImage(NULL, "input.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
BITMAP bitmap;
CBitmap::FromHandle(hBitma
// 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(&bitm
HDC hMemDC = CreateCompatibleDC(dc.GetS
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMem
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. :(
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?
What isn't working exactly? Isn't the bitmap drawn?
ASKER
No it is not drawn. :(
Are you sure the dc.GetSafeHdc() gives the right hDC?
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
project was a success, and answers from Mercurius0 was really helpful. So I will give full credits for him.
ASKER
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
HBITMAP hBitmap=CreateBitmapIndire
And then this to display it
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMem
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