C# WPF图像控件不支持';t显示以编程方式添加/分配的ImageSource
下面的此方法将图像从图像文件路径转换为图像源 下面是我测试过的路径 以下是分配imagesource的方式:C# WPF图像控件不支持';t显示以编程方式添加/分配的ImageSource,c#,wpf,image,C#,Wpf,Image,下面的此方法将图像从图像文件路径转换为图像源 下面是我测试过的路径 以下是分配imagesource的方式: Image_Control.Source = GetImageSourceFromPath(path); 问题是该图像没有显示在WPF图像控件中 任何帮助都将不胜感激。谢谢。通过以下更改,您的代码可以正常工作 public static ImageSource GetImageSourceFromPath(string path) { return new
Image_Control.Source = GetImageSourceFromPath(path);
问题是该图像没有显示在WPF图像控件中
任何帮助都将不胜感激。谢谢。通过以下更改,您的代码可以正常工作
public static ImageSource GetImageSourceFromPath(string path)
{
return new BitmapImage(new Uri(path));
}
Image_Control.Source = GetImageSourceFromPath(path);
如果您使用的是完整路径,则无需指定
UriKind
,否则请使用UriKind.RelativeOrbSolute
,您应将UriKind.RelativeOrbSolute
更改为UriKind.RelativeOrbSolute
。它允许你设置图像的绝对或相对路径。非常感谢你花时间回答我的问题。
public static ImageSource GetImageSourceFromPath(string path)
{
return new BitmapImage(new Uri(path, **UriKind.RelativeOrAbsolute**));
}
public static ImageSource GetImageSourceFromPath(string path)
{
return new BitmapImage(new Uri(path, **UriKind.RelativeOrAbsolute**));
}