一个类库要取本程序集下的图片,作为System.Drawing.Image来使用,exe和图片不在一个程序集,运行时总时报System.ArgumentException异常,通过搜索找到以下方法解决:
报错代码:
System.Drawing.Bitmap sectionImage = null;
sectionImage = new Bitmap("../../Images/horizontal.png");
正常代码:
Uri uri = new Uri("../../Images/horizontal.png", UriKind.RelativeOrAbsolute);
System.Windows.Resources.StreamResourceInfo info = Application.GetResourceStream(uri);
System.Drawing.Image sectionImage = System.Drawing.Image.FromStream(info.Stream);