[Gtk-sharp-list] Gdk.Pixbuf
McP
mariano.cano@hispalinux.es
19 May 2003 20:31:34 +0200
This code works:
using System;
using Gtk;
using GtkSharp;
using Gdk;
class Test {
Test()
{
Gtk.Window window = new Gtk.Window("Test");
window.DeleteEvent += new DeleteEventHandler(Window_Delete);
Pixbuf pixbuf = new Pixbuf(null,"image.png");
try{
window.Add(new Gtk.Image(pixbuf));
}catch(Exception e)
{
Console.WriteLine("Excepcion");
Console.WriteLine(e);
}
window.ShowAll ();
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
Application.Quit ();
}
public static void Main(string[] args)
{
Application.Init ();
new Test();
Application.Run ();
}
}
$ mcs -resource:image.png main.cs -r gtk-sharp -r gdk-sharp
$ mono main.exe
El lun, 19 de 05 de 2003 a las 02:27, Parrish M Myers escribió:
> --- McP <mariano.cano@hispalinux.es> wrote:
> > > Pixbuf pixbuf = new Pixbuf ("lcd.png");
> > > CanvasPixbuf item = new CanvasPixbuf(lcd_canvas.Root());
> > > item.Pixbuf = pixbuf;
> > >
> > > This works great... but I have to include the png file in the
> > current
> > > directory when running the app. If I try to include the file in
> > the
> > > resource string when compiling, i.e.
> > >
> > > mcs ... -resource:lcd.png ...
> > >
> >
> > Try
> > Pixbuf pixbuf = new Pixbuf(null, "lcd.png");
> > ....
> >
> > Now you could store the file inside the assembly as a resource
>
> That seems to produce this error when the resultant exe is created..
> Am I including the resource improperly? I added
> -resource:lcd.png
> to the 'mcs' command...
>
> Unhandled Exception: System.NullReferenceException: A null value was
> found where an object instance was required
> in <0x00090> 00 Gdk.Pixbuf:LoadFromStream (System.IO.Stream)
> in <0x000aa> 00 Gdk.Pixbuf:.ctor (System.Reflection.Assembly,string)
> in <0x000fe> 00 SwTimer.MainWindow:.ctor (ModeType)
> in <0x00198> 00 SwTimer.SwTimer:.ctor (string[],object[])
> in <0x00042> 00 SwTimer.SwTimer:Main (string[])
>
>
--
McP <mariano.cano@hispalinux.es>