PyGTK 中的像素图透明度
如何创建将一个像素值设置为透明的 PyGTK 像素图? 我知道它与创建深度为 1 的像素图并将其设置为遮罩有关,但我发现它要么不执行任何操作,要么在绘制时完全擦除我的像素图。 目前,我制作了一个像素图,
r = self.get_allocation()
p1 = gtk.gdk.Pixmap(self.window,r.width,r.height)
p1_c = p1.cairo_create()
然后使用 Cairo 在其上绘制黑色线条。 我想要做的是让所有未被线条覆盖的区域透明(例如,使白色成为透明颜色),这样当我用draw_drawable将其绘制到窗口时,它会将所有内容留在“下面”完好无损的。
有关此问题的常见问题解答和邮件列表帖子毫无帮助,因为它们已经过时了。 这里一定有人知道!
How can I create PyGTK pixmaps with one pixel value set to transparent? I know it has something to do with creating a pixmap of depth 1 and setting it as a mask, but all I find is that it either does nothing or totally erases my pixmap when drawn. At the moment, I make a pixmap with
r = self.get_allocation()
p1 = gtk.gdk.Pixmap(self.window,r.width,r.height)
p1_c = p1.cairo_create()
then draw black lines all over it using Cairo. What I'd like to be able to do is to have all of the area not covered by lines transparent (making white the transparent colour, say), so that when I draw it to the window with draw_drawable, it leaves everything 'underneath' intact.
The FAQs and mailing list postings regarding this issue are most unhelpful as they are so outdated. Someone must know here!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您无法使用
Pixmap
或Pixbuf
完成您想要的操作,但这里有两种在现有Widget
之上实现涂鸦的策略代码>. 最明显的一个是捕获绘制事件并直接绘制到Widget
的Drawable
上,中间不保留图像:如果您愿意,可以选择第二个选项要获得无需在每次请求重绘时更新的中间 ARGB 图像,可以将图像预渲染到
ImageSurface
。 这是上面的expose_handler
的替代品,它只绘制一次图像:如果这是您正在寻找的东西,我建议更新问题的标题以反映您的真正需求: )。
I don't think you can do what you want with a
Pixmap
orPixbuf
, but here are two strategies for implementing scribbling on top of an existingWidget
. The most obvious one is just to catch the draw event and draw straight onto theWidget
'sDrawable
, with no retained image in the middle:A second option, if you want to have an intermediary ARGB image that you don't have to update each time a redraw is requested, would be to pre-render the image to an
ImageSurface
. Here's a replacement forexpose_handler
, above, that only draws the image once:If this is the sort of thing you're looking for, I would recommend updating the title of the question to reflect your real need :).
看起来您想使用 Pixbuf 而不是 Pixmap。 Pixbuf 包含一个 alpha 设置,它将为您提供透明度,而 Pixmap 则不然。
It looks like you want to use a Pixbuf and not a Pixmap. The Pixbuf includes an alpha setting, which will give you transparency, whereas the Pixmap does not.