This method below converts an image from an image file-path to an ImageSource. Solution found here
public static ImageSource GetImageSourceFromPath(string path)
{
return new BitmapImage(new Uri(path, UriKind.Relative));
}
Here is what a path I've tested looks like
This is how the imagesource gets assigned:
Image_Control.Source = GetImageSourceFromPath(path);
The problem is that the image doesn't show in the WPF image control.
Any help would be much appreciated. Thanks.
Your code will works fine with the following changes.
public static ImageSource GetImageSourceFromPath(string path)
{
return new BitmapImage(new Uri(path));
}
Image_Control.Source = GetImageSourceFromPath(path);
If you are using full path no need to specify the UriKind
,other wise use UriKind.RelativeOrAbsolute
public static ImageSource GetImageSourceFromPath(string path)
{
return new BitmapImage(new Uri(path, **UriKind.RelativeOrAbsolute**));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.