GTK可绘制区域透明背景颜色 [英] GTK drawable area transparent background color

查看:695
本文介绍了GTK可绘制区域透明背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GTK绘图区,我希望有一个图像显示作为它的背景,而其他的东西可以绘制在它上面。

我的第一次尝试就是让我简单地把图像放入一个像素图中,并在绘制其他对象之前绘制它。这导致了物体背景完全覆盖了我的背景图像。

现在我想我需要更改对象的像素图的gtk.gdk.GC,所以它的背景色是透明的。这是我遇到问题的地方。我不知道如何设置gtk.gdk.Color的alpha。

如何设置gtk.gdk.Color的alpha? (或任何其他方式使颜色透明)



如果这个想法似乎不可行,请让我知道。我对GTK很新。

解决方案

我不知道这是否可以帮到你,但我最好的建议是使用 Cairo 一个为高级2D绘图提供跨平台支持的开源2D图形库。它也是绘制2D图形的最简单方法,我认为是
(过去我曾尝试过 GDK ,我认为使用起来要麻烦得多)。

b
$ b

在python中,您可以使用特定的绑定 Pycairo
在这里,您可以通过简单的教程了解更多信息。



针对您的特定问题,详细了解图片



透明度的主要功能是:


  • set_source_rgba(red,green,blue [,alpha = 1.0])


  • paint_with_alpha(alpha) 反射图像在关于trasparency之前链接的同一页面中。


    I have a GTK drawing area and I want to have an image display as the background for it, while other things can be drawn over it.

    My first attempt at this involved me simply taking the image, putting it into a pixmap, and drawing it before I draw other objects. This resulted in the objects backgrounds completely covering my background image.

    Now I am thinking I need to change the object's pixmap's gtk.gdk.GC so the background color it has is transparent. Here is where I am having problems. I do not know how to set a gtk.gdk.Color's alpha.

    How do I set a gtk.gdk.Color's alpha? (or any other way of making the color transparent)

    If this idea seems unlikely to work please let me know. I am pretty new to GTK.

    解决方案

    I don't know if this can help you, but my best advice is to use Cairo: an open source 2D graphics library providing cross-platform support for advanced 2D drawing. It is also the easiest way to draw 2D graphics, I think (I've tried GDK in the past and I thought it was much more tricky to use).

    In python you can use the specific bindings Pycairo. Here you can learn more about it, with easy tutorials.

    For your specific problem, see more about images and trasparency.

    The main function for trasparency are:

    A great summary to learn how to manage images and transparency is in the example Reflected image in the same page linked before about trasparency.

    这篇关于GTK可绘制区域透明背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆