I want paste a (x,y,w,h) subrectangle from src to dest, so that the (x,y) source pixel appears as the (0,0) dest pixel. I’m having a difficulty deciding which of the gazillion overloads does this. Right now my code looks like this, which obviously doesn’t work:
auto_ptr<Gdiplus::Graphics> g(Gdiplus::Graphics::FromHDC(pDC->GetSafeHdc()));
g->DrawImage(png, r.top, r.bottom, r.Width(), r.Height());
g->Flush();
It doesn’t work because the (x,y) source pixel appears as the (x,y) destination pixel, whereas I want it to appear as the (0,0) destination pixel. The source and destination rectangles should have the same size but different offsets, instead of the same offset.
[Edit]
Nevermind, I found the overloaded function I need. Turns all I had to add was the destination (x,y) offset in front, and UnitPixel at the end.
auto_ptr<Gdiplus::Graphics> g(Gdiplus::Graphics::FromHDC(pDC->GetSafeHdc()));
g->DrawImage(png, 0, 0, r.left, r.top, r.Width(), r.Height(), Gdiplus::UnitPixel);
g->Flush();
Anyone would work, they work equally well. They are mostly just aliases for each other. The one I guess you are using would be this one which states that:
Try to set the x and y values to 0 instead, so that the call becomes:
Other than that you would have to be more specific as to what “Doesn’t work”. Is it incorrectly drawn? Is it not drawn at all? Is the png correctly loaded?
If nothing is drawn I suggest you check the return value (which is a Status) from DrawImage which should point you in the correct direction.
EDIT
Ok, so if you don’t want it to be mapped as src(0, 0) to dest(0, 0) I guess you could use this one instead. This will let you decide
Hope this helps.