【发布时间】:2012-10-25 23:01:08
【问题描述】:
我正在为大学的一个项目(为期一个学期)制作二十一点游戏,但我遇到了似乎无法克服的障碍。
我正在尝试加载卡片图像,以便它们可以显示在屏幕上,但这样做我一直非常运气不佳。我有绝对的参考资料;我可以从中加载,但任何从相对路径加载的尝试都会失败。项目必须是独立的;我无法指示我的教授将这些图像复制到根目录。
#if FROMDISK
Uri myUri = new Uri(@"C:\cards\" + getFilename(r, s, "png"), UriKind.Absolute);
PngBitmapDecoder decoder2 = new PngBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bmp = decoder2.Frames[0];
#else
System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream("Blackjack." + getFilename(r, s, "png"));
BitmapImage bmp = new BitmapImage();
bmp.StreamSource = myStream;
#endif
// Draw the Image
im.Source = bmp;
im.Stretch = Stretch.Uniform;
im.Width = CARD_WIDTH;
【问题讨论】: