我正在为大学(一学期)的项目制作一个21点游戏,但遇到了一个无法解决的问题。
我试图加载卡牌图像以便在屏幕上显示,但是我一直都没有成功。我已经掌握了绝对路径;我可以从中加载,但任何尝试从相对路径加载都会失败。该项目必须是独立的;我不能要求我的教授将这些图像复制到根目录。
#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;