我正在为大学项目制作一个二十一点游戏(学期 - 长),我碰到了一块我似乎无法克服的障碍。从相对路径加载图片
我想加载卡图像,以便它们可以在屏幕上显示,但我一直在很这样做的一点运气。我有绝对的参考文献;我可以从这些加载,但任何尝试从相对路径加载失败。该项目必须是独立的;我无法指示我的教授将这些图像复制到根部。
#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;
我应该为哪些文件设置这些属性?设置他们的代码文件似乎是错误的举动(我会说实话:我不知道他们真的) –
@vermiculus更新答案 –
我不知道为什么这么没有通知我所有的这个,但我会试试这个,当我回家! –