我应该使用哪个 Gdiplus::Graphics::DrawImage 函数?
我想将 (x,y,w,h) 子矩形从 src 粘贴到 dest,以便 (x,y) 源像素显示为 (0,0) 目标像素。我很难决定哪一个重载可以做到这一点。现在我的代码看起来像这样,这显然不起作用:
auto_ptr<Gdiplus::Graphics> g(Gdiplus::Graphics::FromHDC(pDC->GetSafeHdc()));
g->DrawImage(png, r.top, r.bottom, r.Width(), r.Height());
g->Flush();
它不起作用,因为 (x,y) 源像素显示为 (x,y) 目标像素,而我希望它显示为 (0 ,0) 目标像素。源矩形和目标矩形应具有相同的大小但不同的偏移量,而不是相同的偏移量。
[编辑] 没关系,我找到了我需要的重载函数。结果我必须添加的只是前面的目标 (x,y) 偏移量和末尾的 UnitPixel。
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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何人都会工作,他们都工作得同样好。他们大多只是彼此的别名。我猜您正在使用的将是这个 其中指出:
尝试将 x 和 y 值设置为 0,以便调用变为:
除此之外,您必须更具体地说明“不起作用”的内容。是不是画错了?是不是根本就没有画出来? png 是否正确加载?
如果没有绘制任何内容,我建议您检查返回值(这是一个 状态)来自 DrawImage,它应该为您指明正确的方向。
编辑
好的,所以如果你不希望它被映射为 src(0, 0) 到 dest(0, 0) 我想你可以使用 这个 代替。这会让你决定
希望这有帮助。
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.