如何将位图 Alphablend 到与其他窗口重叠的所有者绘制的按钮上?
我正在尝试绘制一个带有 alpha 通道(通过 AlphaBlend)的位图作为所有者绘制的按钮的表面。问题是我不知道如何绘制按钮的背景。按钮的位图是圆形的,并且按钮位于绘制矩形位图的静态控件的顶部(通过 SS_BITMAP)。第一次绘制时看起来不错,但随后的绘制最终会对位图及其在 DC 中的剩余部分进行 alpha 混合,因此边缘(alpha 像素所在的位置)会变得难看。我尝试将对话框背景复制到 WM_DRAWITEM 中获得的 DC,但这只能获取对话框背景;它没有让我得到按钮下方的静态控件部分。我该怎么做?
我的位图类似于这个,除了对话框有自定义背景(在 WM_ERASEBKGND 期间绘制的位图)和矩形进一步水平延伸。
I am trying to draw a bitmap with an alpha channel (via AlphaBlend) as the face of an owner-drawn button. The problem is that I'm not sure how to draw the background of the button. The button's bitmap is circular, and the button is on top of a static control that draws a rectangular bitmap (via SS_BITMAP). It looks fine the first time it is drawn, but subsequent drawings end up alphablending the bitmap with its remains in the DC so the edges (where the alpha pixels lie) get ugly. I tried copying the dialog background to the DC I get in WM_DRAWITEM, but that only gets me the dialog background; it does not get me the part of the static control that is under the button. How do I do this?
My bitmaps are similar to this, except the dialog has a custom background (bitmap drawn during WM_ERASEBKGND) and the rectangle extends further out horizontally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了更好的解决方案。它的结构与我之前的解决方案基本相同,只是我没有将设备上下文上已有的内容复制到位图,而是发送所有相关控件 WM_ERASEBKGND 和 WM_PRINTCLIENT 消息。我基于这篇知识库文章中的代码编写了它。
I found a better solution. It's basically the same structure as my previous solution, only instead of copying what's already on the device context to a bitmap I send all the relevant controls WM_ERASEBKGND and WM_PRINTCLIENT messages. I based it off of the code in this KB article.
好吧,我找到了一种适合我的需要的方法;我不知道这是否是理想的解决方案,但如果没有人能提出更好的解决方案,那么我会在几天内接受我自己的答案。
所以这是我正在使用的技巧(从使用 ATL 的 CImage 转换为原始 Win32 API,因此可能会出现一些错误):
Well, I found one method that works for my needs; I don't know if it's the ideal solution, but if nobody can come up with anything better then I'll accept my own answer in a few days.
So here's the trick I'm using (transposed from use of ATL's CImage to raw Win32 APIs, so there could be some mistakes):