开发者

Gtk#: How to convert a Gtk.Image in a Gdk one?

I would like to write a simple 2D game in Mono/Gtk#with MonoDevelop 2.4. My first interest was to display a PNG image for the player character in the Window canvas (later I will respond to keyboard events in order to move it). However, I have found out a disturbing problem here: while I get a Gtk.Image object for the player character, the DrawImage method of the Gdk Window needs a Gdk image. How could I convert the first one to the latter?

public static void ShowImage(Gdk.Window w, Gtk.Image image)
{
    w.DrawImage( Style.ForegroundGC( StateType.Normal ),
                     image,             // ERROR                                    
   开发者_运维问答                  0, 0, image.Pixbuf.Width, image.Pixbuf.Height,
                     image.Pixbuf.Width, image.Pixbuf.Height
    );
}

This is might appear simplistic, but honestly I haven't found the answer yet.


Gtk.Image.ImageProp is a property holding the Gdk.Image held in the Gtk.Image widget.

public static void ShowImage(Gdk.Window w, Gtk.Image image)
{
    w.DrawImage( Style.ForegroundGC( StateType.Normal ),
                     image.ImageProp,             // TRY THIS                              
                     0, 0, image.Pixbuf.Width, image.Pixbuf.Height,
                     image.Pixbuf.Width, image.Pixbuf.Height
    );
}

Here is a link to the GTK# documentation.


Gtk.Image is a widget (or a control in winforms terminology).

see: http://library.gnome.org/devel/gtk/unstable/GtkImage.html

From your problem description I don't think you want to be using a Gtk.Image, but a Gdk.Image.

IE. change your ShowImage method to: public static void ShowImage(Gdk.Window w, Gdk.Image image)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜