我正在尝试从网络加载图标/图像并将它们放入我的 TreeView 中。我有以下代码(如下),但每次运行它都会引发异常。我不明白我在这里做错了什么。你能帮我写正确的代码吗?
public void ImgCellRenderer(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gdk.Pixbuf icon = Gdk.PixbufLoader.LoadFromResource("http:\\\\www.free-icons-download.net\\images\\strawberry-icon-37824.png").Pixbuf;
(cell as Gtk.CellRendererPixbuf).Pixbuf = icon;
}
完整的例外是:
System.ArgumentException: 'http:\\www.free-icons-download.net\images\strawberry-icon-37824.png' is not a valid resource name of assembly 'MDM, Version=1.0.5862.27549, Culture=neutral, PublicKeyToken=null'.
at Gdk.PixbufLoader.InitFromAssemblyResource (System.Reflection.Assembly assembly, System.String resource) [0x00051] in /private/tmp/source-mono-mac-4.2.0-branch-64/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/gdk/generated/PixbufLoader.custom:104
at Gdk.PixbufLoader..ctor (System.Reflection.Assembly assembly, System.String resource) [0x00020] in /private/tmp/source-mono-mac-4.2.0-branch-64/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/gdk/generated/PixbufLoader.custom:94
at Gdk.PixbufLoader.LoadFromResource (System.String resource) [0x00007] in /private/tmp/source-mono-mac-4.2.0-branch-64/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/gdk/generated/PixbufLoader.custom:142
at MDM.TweetSelectorWidget.ImgCellRenderer (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, TreeModel model, TreeIter iter) [0x00006] in /Users/tribehive/Projects/MDM/MDM/TweetSelectorWidget.cs:160
at GtkSharp.TreeCellDataFuncWrapper.NativeCallback (IntPtr tree_column, IntPtr cell, IntPtr tree_model, IntPtr iter, IntPtr data) [0x0002c] in /private/tmp/source-mono-mac-4.2.0-branch-64/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/gtk/generated/GtkSharp.TreeCellDataFuncNative.cs:57
at GLib.ExceptionManager.RaiseUnhandledException (System.Exception e, Boolean is_terminal) [0x0003b] in /private/tmp/source-mono-mac-4.2.0-branch-64/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/gtk-sharp-2.12.21/glib/ExceptionManager.cs:58
at GtkSharp.TreeCellDataFuncWrapper.NativeCallback (IntPtr tree_column, IntPtr cell, IntPtr tree_model, IntPtr iter, IntPtr data) [0x00051] in /private/tmp/source-mono-mac-4.2.0-branch-64/bockbuild-