Jump to content

  • Log In with Google      Sign In   
  • Create Account


[ Win32 | DevIL ] Cannot get ilutWinLoadImage to work


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 programering   Members   -  Reputation: 105

Like
0Likes
Like

Posted 09 September 2012 - 10:32 AM

Hi.

I am having a trouble to properly load an image with the DevIL's ilutWinLoadImage(hDC)function. On my first attempt with displaying the loaded image it didn't show up at all. But later I managed to get the image to display but now just in black&white though it originally is in colors.

Here is an approximately holistic idea of how I try to get it to work, taken from my originally very messed up code:

In my function that loads the image HBITMAP/HDC:
m_hImageDC = CreateCompatibleDC(NULL);	 // Seemed to be required before passing it.
m_hImageBmp = ilutWinLoadImage(L"TheImage.bmp",m_hImageDC);
SelectObject(m_hImageDC, m_hImageBmp);  // <-- This was added in the second attempt which got it to show up, but just in b&w.

In the WindowProc's WM_PAINT msg of the window to display the image:
case WM_PAINT:
l_hWndDC = BeginPaint(p_hWnd, &paintstruct);
BitBlt(l_hWndDC, 100, 100, 240, 40, l_drawContext->GetTheImageHDC(), 0, 0, SRCCOPY);
EndPaint(p_hWnd, &paintstruct);

What procedures(additionally Win32 function calls) do you usually have to make to get this ilutWinLoadImage(hDC) to work as it is supposed to?

Thanks.

Edited by programering, 09 September 2012 - 10:34 AM.


Sponsor:

#2 programering   Members   -  Reputation: 105

Like
0Likes
Like

Posted 09 September 2012 - 01:53 PM

Turns out that I found the documented solution for this problem while goggling once again though I took myself a long time to try looking(through numerous unsuccessive search queries) for it and solving it by myself before starting this topic. So typical. But I'll provide the source for it so that others that might encounter the same problem can benefit from this one:

http://support.microsoft.com/kb/139165 via http://forums.codegu...SetBitmapBits()

Now Solved.

Edit:

Actually the solution will be in this case: (the correct Win32 API call procedures to get ilutWinLoadImage to work)
hdc = GetDC(NULL);   // or: hdc = l_hWndDC;
hdcMem = CreateCompatibleDC(hdc);
hBitmap = ilutWinLoadImage(L"TheImage.bmp",hdc);     // <-- a HDC retrieved by GetDC of your destination DC, Not by CreateCompatibleDC.
SelectObject(hdcMem, hBitmap);

BitBlt(l_hWndDC,100,100,240,40,hdcMem,0,0,SRCCOPY);

// And don't forgetting to release and delete the respective HDC's when done with them.

Edited by programering, 10 September 2012 - 12:57 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS