[英]SplashScreen IOException
SplashScreen s = new SplashScreen(System.Reflection.Assembly.GetExecutingAssembly(),"splash.png");
s.Show(false);
when invoking s.Show()
whether the parameter is false
or true
, it throws an IOException
with the message 在调用
s.Show()
无论参数是false
还是true
,它都会抛出带有消息的IOException
Cannot locate resource 'splash.png'
找不到资源'splash.png'
even though that splash.png is added to resources and its Build Action is Resource . 即使将splash.png添加到资源中,其Build Action也是Resource 。
I have noticed many problems when using images in WPF, also with Image
control. 我在WPF中使用图像时也发现了许多问题,也使用了
Image
控件。
According to the principle "My Code doesn't work and I don't know why. My code Works and I don't know why", I have solved the problem. 根据原则“我的代码不起作用,我不知道为什么。我的代码工作,我不知道为什么”,我已经解决了这个问题。
First I have made the Build Action of the splash image as Resource . 首先,我将启动图像的构建操作设置为资源 。 (Putting the image as Embedded Resource didn't solved the problem).
(将图像作为嵌入式资源放置并没有解决问题)。
Second, My code is : 第二,我的代码是:
SplashScreen s = new SplashScreen("resources/splash.png");
s.Show(false);
/* do some things */
s.Close(Timespan.FromMilliseconds(300));
even though that splash.png is added to resources and its Build Action is Resource.
即使将splash.png添加到资源中,其Build Action也是Resource。
Wrong build action, make it Embedded Resource
. 错误的构建操作,使其成为
Embedded Resource
。 If you still have trouble then use ildasm.exe to look at the assembly manifest for the .mresource directive to ensure that the resource got properly embedded with the expected name. 如果仍有问题,请使用ildasm.exe查看.mresource指令的程序集清单,以确保资源正确嵌入了预期名称。
Or use a file, following these how-to steps . 或者按照这些操作步骤使用文件。 Generally the more sane approach since it doesn't make that much sense to have a large resource occupy address space for the life of the program when it is only needed for a short amount of time at the start of the program.
一般来说,这是一种更理智的方法,因为当程序开始时只需要很短的时间就可以使大量资源占用程序生命周期的地址空间。
try with explicitly specifying the assembly name, even though the caller was in the same assembly as the resource. 尝试显式指定程序集名称,即使调用程序与资源位于同一程序集中。
Here's how it looks with a Pack URI syntax: 以下是使用Pack URI语法的外观:
pack://application:,,,/MyAssemblyName;component/MyResourcesFolder/MyImage.png
http://msdn.microsoft.com/en-us/library/aa970069.aspx http://msdn.microsoft.com/en-us/library/aa970069.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.