如何使用 GDI 实现图层?

发布于 2024-08-14 17:14:56 字数 74 浏览 3 评论 0原文

我想实现像Photoshop一样的橡皮功能,但我希望橡皮只是擦除背景上绘制的形状而不修改背景。现在背景是图像,所以我不能使用单色画笔。

I want to implement a rubber function just like photoshop, but I hope the rubber just to erase the shapes that drawed on background without modifying the background. Now the background is a image so I can't use the brush with the single color.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪冰清 2024-08-21 17:14:56

您需要将图像的每一层存储在自己的缓冲区中,然后将它们组合起来输出。因此背景将在一个 Image 对象中,而形状将在另一个 Image 对象中。当您收到 WM_Paint 消息时,您必须将两个图像合并为一个并将其输出(或者您必须将图像预先组合在内存中的第三个 Image 对象中)。

You need to store each layer of the image in its own buffer, and then combine them to output it. So the background would be in one Image object and the shape would be in another Image object. When you get the WM_Paint message, you would have to combine both images into one and output that (or you would have to have the images pre-combined in a third Image object in memory).

咿呀咿呀哟 2024-08-21 17:14:56

如果你只想画简单的线条/形状,比如橡皮筋盒,老式的方法是使用异或绘画。这会“反转”绘制位置的颜色,因此第二次绘制相同的形状会擦除它并返回原始图像。

如今,计算机的功能更加强大,因此我们倾向于(正如戴夫·马克尔所说)将两个单独的图像组合到屏幕上(您只需将正在编辑的实际图像存储在屏幕外位图中)。这允许您使用任何颜色/透明度绘制叠加层,这样您就可以使其看起来更好。

If you just want to draw simple lines/shapes like a rubber-banding box, the old-fashioned way is to use exclusive-or painting. This "inverts" the colours where it is drawn, so drawing the same shape a second time erases it and returns the original image.

These days computers are much more powerful so we tend (as Dave Markle has said) to just combine two separate images onto the screen (you just have to store the actual image you are editing in an offscreen bitmap). This allows you to draw the overlay using any colour/transparency, so you can make it look much nicer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文