不是程序集的有效资源名称



我正在使用Xamarin Studio和GTK#(.NET(。我有以下问题: 我已经制作了一个应用程序,我需要(动态地(下载网页图像(favicons(并在Gtk.Image小部件中显示它们。当我尝试执行此操作时,出现以下错误:

System.ArgumentException: 'myfile.ico' is not a valid resource name of assembly 'myApp, Version=1.0.6742.24722, Culture=neutral, PublicKeyToken=null'.
at at Gdk.PixbufLoader.InitFromAssemblyResource(Assembly assembly, String resource)
at at Gdk.PixbufLoader..ctor(Assembly assembly, String resource)
at at Gdk.Pixbuf..ctor(Assembly assembly, String resource)
at at Gdk.Pixbuf.LoadFromResource(String resource)

如果我在下载后在资源文件夹中添加网站图标,它可以工作,但我需要动态地执行此操作(如果我添加一个新站点,我想在那里看到它的图标..(。 代码:

using (WebClient client = new WebClient())
{
client.DownloadFile(new Uri("https://google.com/favicon.ico", 
Directory.GetCurrentDirectory() + "....Resgoogle.ico");
}
faviconImage.Pixbuf = Gdk.Pixbuf.LoadFromResource("myApp.Res.myfile.ico");

图像在文件夹中(我可以看到它,一切都很好(,但是如果我不将其(手动(包含在资源文件夹中,我就无法使用它......

请帮助我:'(

Pixbuf.LoadFromResource仅从嵌入的程序集资源加载图像数据。创建程序集后,不能向程序集添加资源。

若要从文件创建Pixbuf,请使用支持映像的文件路径或使用文件流的文件路径的.ator

像这样:

var filePath = Path.Combine(Directory.GetCurrentDirectory(), "myDownloadIcon.ico");
var newPixBuf = new PixBuf(filePath):
faviconImage.Pixbuf = newPixBuf;

相关内容

最新更新