【发布时间】:2013-08-28 10:52:16
【问题描述】:
我像这样将 URL 保存在数据库中
~/Images/Questions/drink.png
所以当我在我的 WPF 应用程序中检索它时,我尝试这样做:
Image img = new Image();
img.Width = Double.NaN;
img.Height = Double.NaN;
// string fullFilePath = Path.Combine(@"C:\Users\apr13mpsip\Documents\Visual Studio 2010\Projects\iStellarMobile\iStellarMobile\Images\Questions", lstQuestion[i].ImageURL.Substring(1));
string fullFilePath = @"C:\Users\apr13mpsip\Documents\Visual Studio 2010\Projects\iStellarMobile\iStellarMobile\Images\Questions\drink.png";
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(fullFilePath, UriKind.Relative);
bi.EndInit();
img.Source = bi;
wrapPanel1.Children.Add(img);
lstQuestion[i].ImageURL 是我从数据库中检索的 URL。但它不起作用......当我运行它时它什么也不显示,所以我通过手动输入整个目录来尝试完整路径,但它仍然不起作用,我这里出了什么问题?
当我调试它时,它只显示 Images\Questions\drink.png 而不是完整路径
当我使用时
Path.Combine(@"C:\Users\apr13mpsip\Documents\Visual Studio 2010\项目\iStellarMobile\iStellarMobile", lstQuestion[i].ImageURL.Substring(1));
,它说 URL 无法确定,当我调试它时,它只读取为 Images\Questions\drink.png 而不是完整路径。
【问题讨论】:
-
您在哪里显示图像?以及如何?
-
你已经得到了完整的路径,你应该使用 UriKind.Absolute 而不是 UriKind.Relative
-
当我使用 Absolute 时,它说 URL 格式无法确定,@Shaharyar 我试图通过添加它来显示在包装面板上
-
该 URL 是指网络服务器上的图像还是本地文件系统上的图像?
-
请确保数据库中的 url 不以“/”开头,如果是,请使用 x = x.Substring(1); 将其删除