如何使用 GDI 实现图层?
我想实现像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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将图像的每一层存储在自己的缓冲区中,然后将它们组合起来输出。因此背景将在一个 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).
如果你只想画简单的线条/形状,比如橡皮筋盒,老式的方法是使用异或绘画。这会“反转”绘制位置的颜色,因此第二次绘制相同的形状会擦除它并返回原始图像。
如今,计算机的功能更加强大,因此我们倾向于(正如戴夫·马克尔所说)将两个单独的图像组合到屏幕上(您只需将正在编辑的实际图像存储在屏幕外位图中)。这允许您使用任何颜色/透明度绘制叠加层,这样您就可以使其看起来更好。
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.