Blt() 创建图层效果。 不工作。 我使用了错误的逻辑函数还是什么?
我有一个窗口,由各种对象绘制以创建分层效果(想象一下平视显示器,其中一个对象绘制指南针,另一个对象绘制网格线,另一个对象绘制高度计读数等)。 因此,每个对象都有一个用于绘制的黑色内存位图。 当我调用该对象的 Draw 函数时,内存位图将被传输到应用程序窗口。 内存位图一开始都是黑色的,对象在其上绘制。 黑色是透明颜色,因此被遮盖。 结果是叠加效果。
因此,我一直在 blt() 函数中使用 OR 作为逻辑函数,并且它有效。 但是,我注意到,如果前一层被漆成白色,那么在它上面绘制的图层看起来就像是在前一层的下面。 白色是唯一会发生这种效果的颜色。 所有其他颜色都绘制正确(也就是说,该图层看起来像是绘制在前一个颜色之上,依此类推)。 有人见过这种现象吗?
I have one window that is drawn to by various objects to create a layered effect (think of a heads up display where one object draws a compass, the other draws the grid lines, another the altimeter reading etc). So, each object has a black memory bitmap that it draws to. When I call that objects Draw function, the memory bitmap is blitted to the application window. The memory bitmaps are all black to begin with and the object draws on it. Black is the transparent color so it is masked off. The result is an overlay effect.
So, I've been using OR as my logical function in the blt() function and it has worked. But, I've noticed that if the previous layer has painted white, then the layer that draws on top of it comes out looking as if it is beneath the previous layer. The white(ish) colors are the only ones where this effect occurs. All other colors are painted correct (that is, the layer looks like it is painted on top of the previous one and so forth). Has anyone seen this phenomenon?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您为此使用了错误的函数。 如果您尝试覆盖的像素恰好是黑色,则将 BitBlt 与逻辑 OR 一起使用将起作用,但如果您将两种非零颜色与 OR 组合,则会得到奇怪的结果。 尝试改用TransparentBlt。 该函数允许您明确指定哪种颜色应该是透明的。
You're using the wrong function for this. Using a BitBlt with a logical OR will work if the pixel you're trying to overwrite happens to be black, but if you combine two non-zero colours with OR, then you'll get strange results. Try using TransparentBlt instead. That function lets you explicitly specify which colour is supposed to be transparent.
我已经有一段时间没有使用 GDI 了,但我假设您正在谈论 BitBlt 函数,对吧? 你们究竟在做什么? 我记得 BitBlt 仅采用源和目标 HDC、矩形和一些标志。
您是否对位图的位进行“或”运算以实现叠加效果? 这是行不通的,因为 OR 运算符既具有结合性又具有交换性。 换句话说,
这
意味着您“或”事物的顺序对结果没有影响。 您只需一次对每个位图进行位图传输即可获得叠加效果。
如果这没有帮助我道歉,我可能完全误解了你的问题,因为我已经有几年没有看过 GDI 了。
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,
and
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.
为什么要费心 BitBlt 和 OR? 只需使用 AlphaBlend(),它即可为您提供整个字节的透明度。
Why bother with BitBlt and OR? Just use AlphaBlend(), which gives you a whole byte of transparency.
您想要做的事情需要两个位图:一个用于屏蔽目标位图的部分(使用像素级与),然后第二个用于按像素或将覆盖层中的颜色复制到目标上。
手动执行此操作,您需要从叠加位图制作单色蒙版,透明部分为白色,不透明部分为黑色。 AND 蒙版与目的地,然后或原始叠加层中的颜色数据。
屏幕和蒙版或覆盖
如果这是全屏内容,您可能需要在离屏位图中进行合成以避免闪烁。
Peter Ruderman 使用TransparentBlt 的建议可能是一个不错的建议,尽管我自己从未尝试过。
What you want to do requires two blits: one to mask out the portions of the destination bitmap (using pixelwise AND), and then a second one to pixelwise OR the colors from the overlay onto the destination.
Do do this manually, you need to make a monochrome mask from your overlay bitmap, with white in the transparent parts and black in the opaque parts. AND the mask with the destination, then OR the color data from your original overlay.
screen AND mask OR overlay
And if this is for full-screen stuff, you may want to do the composition in an off-screen bitmap to avoid flicker.
Peter Ruderman's suggestion to use TransparentBlt is probably a good one, though I've never tried it myself.