1
我在C#,.Net 4.0中工作,但我有一个Windows窗体应用程序。 我想从Uri
创建Image
对象。我找到的每个链接都是关于WPF应用程序,但我在Windows窗体中工作。来自Windows窗体应用程序中的URI的图像
Image x = new Image();
//this doesn't work for me
我在C#,.Net 4.0中工作,但我有一个Windows窗体应用程序。 我想从Uri
创建Image
对象。我找到的每个链接都是关于WPF应用程序,但我在Windows窗体中工作。来自Windows窗体应用程序中的URI的图像
Image x = new Image();
//this doesn't work for me
您的代码仅使用默认属性创建一个新的Image
对象。我没有看到你在哪里尝试使用Uri
。
使用WebClient.OpenRead
从Uri
和Image.FromStream
中获取流以从中获取图像。
var wc = new WebClient();
Image x = Image.FromStream(wc.OpenRead(uri));
@ user966638 - 确实,这就是为什么我更新了我的答案。 – Oded
我得到了一个WebException: Uri myUri = slidePart.ImageParts.ElementAt(0).Uri; var wc = new WebClient(); Image pic1 = Image.FromStream(wc.OpenRead(myUri)); –
@ user966638 - 你确定你有一个有效的'Uri',并且你不需要指定任何凭据来获得它?你能编辑你的问题并发布完整的异常细节吗? – Oded