[英]Parameter not valid - System.argumentexception - Image Handling
the following piece of code worked fine all day yesterday 以下代码段昨天全天工作正常
public Image getImage()
{
String connectionString = "URL GOES HERE, CANT POST WORK DATA";
Image img;
HttpWebRequest request = WebRequest.Create(connectionString) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
img= Image.FromStream(reader.BaseStream);
}
return img;
}
It gets an image from a webservice provided by work, i used it a lot yesterday for the day but now all i get is the exception stated in the header on the line 它从工作提供的Web服务中获取图像,昨天我一天经常使用它,但现在我所得到的只是该行标题中所述的异常
img= Image.FromStream(reader.BaseStream);
the problem is its working for everyone else apart from me (you can manually type the url in to your browser and it displays the image in there, this is not working for me either) 问题是它对我以外的其他人都有效(您可以在浏览器中手动输入网址,并在其中显示图像,这对我也不起作用)
Does anyone have any ideas? 有人有什么想法吗?
Thanks 谢谢
Two things: 两件事情:
1) The StreamReader is of not use, it's only used for Text streams, you can use response.GetResponseStream() directly 1)不使用StreamReader,它仅用于Text流,可以直接使用response.GetResponseStream()
2) The doc for Image.FromStream available here says "You must keep the stream open for the lifetime of the Image.", so you must not create the stream with the 'using' statement, as it will be closed at block end. 2)Image.FromStream的文档在此处显示为 “您必须在Image的生存期内保持流处于打开状态。”,因此您不得使用'using'语句创建流,因为它将在块末关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.