3

我有一个由各种对象绘制的窗口以创建分层效果(想想平视显示器,其中一个对象绘制指南针,另一个绘制网格线,另一个绘制高度计读数等)。因此,每个对象都有一个黑色的内存位图来绘制。当我调用该对象的 Draw 函数时,内存位图被传送到应用程序窗口。内存位图一开始都是黑色的,对象在上面绘制。黑色是透明色,所以被遮住了。结果是叠加效果。

所以,我一直在 blt() 函数中使用 OR 作为我的逻辑函数,它已经奏效了。但是,我注意到如果前一层涂成白色,那么在它上面绘制的层看起来就好像它在前一层下面。白色(ish)颜色是唯一出现这种效果的颜色。所有其他颜色都被正确绘制(也就是说,该图层看起来像是在前一个颜色之上绘制的,依此类推)。有人见过这种现象吗?

4

4 回答 4

2

您为此使用了错误的功能。如果您尝试覆盖的像素恰好是黑色,则使用带有逻辑 OR 的 BitBlt 将起作用,但如果您将两种非零颜色与 OR 结合使用,则会得到奇怪的结果。尝试改用 TransparentBlt。该函数允许您明确指定哪种颜色应该是透明的。

于 2009-06-08T20:05:30.560 回答
1

It's been awhile since I've used the GDI, but I'm assuming you're talking about the BitBlt function, right? What exactly are you ORing together? As I recall BitBlt just takes a source and destination HDC, rectangles and some flags.

Are you ORing the bits of the bitmaps to achieve the overlay effect? That won't work, as the OR operator is both associative and commutative. In other words,

a | b == b | a

and

(a | b) | c == a | (b | c)

which means that the order in which you OR things has no effect on the outcome. You just need to blit each bitmap one at a time in order to get an overlay effect.

If this doesn't help I apologize, I may have completely misinterpreted your question as it has been a few years since I've even looked at the GDI.

于 2009-06-08T18:45:46.510 回答
0

您想要做的事情需要两个 blit:一个用于屏蔽目标位图的部分(使用逐像素与),然后是第二个逐像素 OR 将叠加层中的颜色添加到目标位置。

手动执行此操作,您需要从叠加位图制作单色蒙版,透明部分为白色,不透明部分为黑色。AND 蒙版与目的地,然后 OR 来自原始叠加层的颜色数据。

screen AND mask OR overlay

如果这是全屏内容,您可能希望在屏幕外位图中进行合成以避免闪烁。

Peter Ruderman 关于使用 TransparentBlt 的建议可能是一个不错的建议,尽管我自己从未尝试过。

于 2009-06-10T18:16:27.673 回答
0

为什么要打扰 BitBlt 和 OR?只需使用 AlphaBlend(),它会为您提供一整字节的透明度。

于 2009-06-10T12:15:55.653 回答