C++/MFC - Problem with GDI+ Bitmap::GetHBITMAP()
-
In my original post I checked the
Color
object at the point labeled "b:" just before the call toGetHBITMAP()
and as far as I can tell by looking in the debugger the values are set properly. It does not change after the call toGetHBITMAP()
yet the colour in the final bitmap is always wrong.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
strange. Out of curiosty, try grabbing a few pixels from the bitmap, just on the offchance it's being corrupted while being sent to your ImageViewer ( highly unlikely I know ). Other from that I can't think of anything.
-
Mark Salsbery wrote:
Got interrupted by g/f for lunch and a movie LOL.
Yeah, we all got lives that pull us away from our code. I actually have to go curling now so I will not be able to look at this any further for the next couple hours.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
Isn't it too cold to be curling? :) This looks like a bug to me. A "Copy/Paste the line of code for the blue component twice for the red and green components but forget to change it to access those components" kind of thing... I'm getting the same results - only the blue component of the passed Color gets used in the destination color. hmm Mark
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
-
Isn't it too cold to be curling? :) This looks like a bug to me. A "Copy/Paste the line of code for the blue component twice for the red and green components but forget to change it to access those components" kind of thing... I'm getting the same results - only the blue component of the passed Color gets used in the destination color. hmm Mark
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
Mark Salsbery wrote:
I'm getting the same results
Well that sucks. That either means we are both doing something wrong or GetHBITMAP is seriously flawed. As I doubt it is our fault I am going to go with the flawed theory. Thanks for looking into it. I will just have to use the work around that I made, not as handy but it does work. Basicly I create a HBITMAP of the required dimensions, fill it with the background colour, then use Gdiplus::Graphics::DrawImage to draw the image overtop of it.
bool CImageViewerDoc::LoadImageFile(CString FilePath)
{
Gdiplus::Bitmap Image((LPCWSTR)CT2W(FilePath));
ShowGraphic(Image, _T("%s loaded into Gdiplus::Image"), FilePath);CRect Size(0, 0, Image.GetWidth(), Image.GetHeight()); pja::CBitmap Bitmap(NULL, Size.right, Size.bottom); pja::CCompatibleDC dc; SelectObject(dc, Bitmap); FillRect(dc, &Size, CBrush((COLORREF)AfxGetMainWnd()->SendMessage(WMU\_GETBGCOLOUR, 0, 0))); ShowGraphic(dc, \_T("memory dc after the fillrect call")); Gdiplus::Graphics Graphics(dc); if (Gdiplus::Ok == Graphics.DrawImage(&Image, 0, 0)) { ShowGraphic(Bitmap, \_T("%s in HBITMAP"), FilePath); CImageData ImageData(Bitmap); Images.push\_back(ImageData); IsImageFile = true; return true; } return false;
}
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
Mark Salsbery wrote:
I'm getting the same results
Well that sucks. That either means we are both doing something wrong or GetHBITMAP is seriously flawed. As I doubt it is our fault I am going to go with the flawed theory. Thanks for looking into it. I will just have to use the work around that I made, not as handy but it does work. Basicly I create a HBITMAP of the required dimensions, fill it with the background colour, then use Gdiplus::Graphics::DrawImage to draw the image overtop of it.
bool CImageViewerDoc::LoadImageFile(CString FilePath)
{
Gdiplus::Bitmap Image((LPCWSTR)CT2W(FilePath));
ShowGraphic(Image, _T("%s loaded into Gdiplus::Image"), FilePath);CRect Size(0, 0, Image.GetWidth(), Image.GetHeight()); pja::CBitmap Bitmap(NULL, Size.right, Size.bottom); pja::CCompatibleDC dc; SelectObject(dc, Bitmap); FillRect(dc, &Size, CBrush((COLORREF)AfxGetMainWnd()->SendMessage(WMU\_GETBGCOLOUR, 0, 0))); ShowGraphic(dc, \_T("memory dc after the fillrect call")); Gdiplus::Graphics Graphics(dc); if (Gdiplus::Ok == Graphics.DrawImage(&Image, 0, 0)) { ShowGraphic(Bitmap, \_T("%s in HBITMAP"), FilePath); CImageData ImageData(Bitmap); Images.push\_back(ImageData); IsImageFile = true; return true; } return false;
}
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
PJ Arends wrote:
As I doubt it is our fault I am going to go with the flawed theory.
I agree :) Good workaround. All that code to do it kinda makes me feel like I'm not getting anything out of GDI+ though :rolleyes: I posted sample code on MS site as well just for the heck of it. I do think it's a bug though. Mark
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
-
PJ Arends wrote:
As I doubt it is our fault I am going to go with the flawed theory.
I agree :) Good workaround. All that code to do it kinda makes me feel like I'm not getting anything out of GDI+ though :rolleyes: I posted sample code on MS site as well just for the heck of it. I do think it's a bug though. Mark
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
Mark Salsbery wrote:
I posted sample code on MS site as well just for the heck of it.
Good idea. Can you supply a link? I would like to follow that thread as well.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
Mark Salsbery wrote:
I posted sample code on MS site as well just for the heck of it.
Good idea. Can you supply a link? I would like to follow that thread as well.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
The link[^] It hasn't generated much interest yet. Hopefully I used the most appropriate forum. There's so many I get bored half way through the list. :laugh:
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
-
Mark Salsbery wrote:
I posted sample code on MS site as well just for the heck of it.
Good idea. Can you supply a link? I would like to follow that thread as well.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
Ok that was the wrong place to post that question :rolleyes: I reposted here[^] And I thought there was alot of forums at the other one...
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
-
Ok that was the wrong place to post that question :rolleyes: I reposted here[^] And I thought there was alot of forums at the other one...
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
-
Ok that was the wrong place to post that question :rolleyes: I reposted here[^] And I thought there was alot of forums at the other one...
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it." (Rex Kramer "Airplane!")
Here[^] is an MSDN forum entry that talks about a blue "halo" around images and an admitted bug in the GetHBITMAP function. It is dated from May 2005 so one would figure there would be a fix by now. I will keep looking.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
Here[^] is an MSDN forum entry that talks about a blue "halo" around images and an admitted bug in the GetHBITMAP function. It is dated from May 2005 so one would figure there would be a fix by now. I will keep looking.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
Thanks for the link! I would guess it's a pretty simple bug to fix - maybe it doesn't get reported. It may not be often that we (programmers) need a HBITMAP from a Gdiplus::Bitmap. Still, I never know - I may want to do it tomorrow and it's not going to work :mad: One reply so far on the MS GDI board but it wasn't useful. Thanks for the update! Mark
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")
-
Here[^] is an MSDN forum entry that talks about a blue "halo" around images and an admitted bug in the GetHBITMAP function. It is dated from May 2005 so one would figure there would be a fix by now. I will keep looking.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
-
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic21736.aspx[^]
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
:laugh::laugh: Thank you! I am SO glad someone else argued with him - I know that's where it was going in my thread on MSDN (with the same guy!). Anyway, did you draw any conclusion from all that? Mark
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")
-
:laugh::laugh: Thank you! I am SO glad someone else argued with him - I know that's where it was going in my thread on MSDN (with the same guy!). Anyway, did you draw any conclusion from all that? Mark
"Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")
Mark Salsbery wrote:
Anyway, did you draw any conclusion from all that?
Yeah, that that guy is extremely stubborn:doh: If he is right, and the result we are seeing is the expected result, then the designers of GetHBITMAP should be shot as it makes absolute no sense.:sigh: I think I will just use my workaround as all I have been able to find on the subject is some people complaining about the bug, but no one being able to point to a hotfix or easy to implement solution (hooking the Gdiplus dll is not an easy solution). I will continue to watch these threads but I will not hold my breath waitng for a solution.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!