如何在DrawingArea中绘制GTK股票图像

时间:2013-09-23 08:43:17

标签: c# gtk gtk#

我在GTK#中写了一个简单的文件浏览器。我想在DrawingArea中绘制目录的库存图像。我不想加载外部图像。我开始使用Gdk.PixBuf,但无法弄清楚如何加载库存图片。

2 个答案:

答案 0 :(得分:2)

有几种方法可以做到这一点,但我相信gtk_icon_theme_load_icon()是一个不被弃用且与大多数GTK +版本兼容的方法。您需要一个图标GtkIconTheme作为参数,但在大多数情况下,gtk_icon_theme_get_default()就是您想要的。图标名称参数来自Icon naming spec

答案 1 :(得分:0)

好的,所以在DrawingArea中渲染库存项目有点不稳定。

private Gdk.GC gc;
private Gdk.Pixbuf pixbuf;

public MainWindow (): base (Gtk.WindowType.Toplevel)
{
    Build ();
    this.gc = new Gdk.GC((Gdk.Drawable)this.browserArea.GdkWindow);
//the method below does the trick. It is the only method I found that will return
//a valid pixbuf, so you can easily draw with the "usual" DrawPixbuf method in the 
//ExposeEvent
    this.pixbuf = RenderIcon(Gtk.Stock.Cdrom, IconSize.Dialog, "");
    this.browserArea.ExposeEvent += new ExposeEventHandler(OnExposeEvent);
}

protected void OnExposeEvent(object sender, ExposeEventArgs args){
    this.browserArea.GdkWindow.DrawPixbuf(this.gc, this.pixbuf,0,0,20,20,-1,-1,Gdk.RgbDither.None,0,0);
}