System.UriFormatException

本文关键字:UriFormatException System | 更新日期: 2023-09-27 18:37:25

我在 c# System.URI.FormatExption 中遇到了一个问题

为了清楚起见,我正在使用一种 Matlab 方法,该方法Segseuil它返回一个图片路径result 。我想为其他用户保存此图像,但出现了异常。

private void segmenter(object sender, RoutedEventArgs e)  {
 s.SegSeuil(0, (MWCharArray)name, (MWCharArray)result);
 BitmapImage tmp = new BitmapImage(new Uri(result));  // exception here 
 image.Source = tmp;
}

System.UriFormatException

如果result是相对路径,例如图像.jpg则必须使用UriKind.Relative

BitmapImage tmp = new BitmapImage(new Uri(result, UriKind.Relative));

RelativeOrAbsolute

BitmapImage tmp = new BitmapImage(new Uri(result, UriKind.RelativeOrAbsolute));

确保结果文件存在于.exe文件中或包含 exe 文件的文件夹中。


如果result是绝对路径,例如:D:''image.jpg则可以使用:
BitmapImage tmp = new BitmapImage(new Uri(result));

或:

BitmapImage tmp = new BitmapImage(new Uri(result, UriKind.Absolute));

或:

BitmapImage tmp = new BitmapImage(new Uri(result, UriKind.RelativeOrAbsolute));
相关文章:
  • 没有找到相关文章