简体   繁体   English

参数无效-System.argumentException-图像处理

[英]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.

相关问题 System.ArgumentException:“参数无效”内存流到图像 - System.ArgumentException: "Parameter is not Valid" Memorystream to Image System.ArgumentException:参数无效 - System.ArgumentException: Parameter is not valid DrawToBitmap - System.ArgumentException:参数无效 - DrawToBitmap - System.ArgumentException: Parameter is not valid 更新 Access 数据库后检索图像时出现问题(System.ArgumentException:'参数无效。') - Problem retrieving the image after updating the Access database (System.ArgumentException: 'Parameter is not valid.') 给出“System.ArgumentException:'参数无效。' " 当我从数据库中检索图像时 - Gives "System.ArgumentException: 'Parameter is not valid.' " when i retrieving image from database System.ArgumentException:“参数无效。” 在 C# 中从 SQL Server 获取图像 - System.ArgumentException: 'Parameter is not valid.' in C# get image from SQL Server ImageResizer-转换PSD文件时出错-System.ArgumentException:参数无效 - ImageResizer - Error converting PSD file - System.ArgumentException: Parameter is not valid System.ArgumentException:参数无效。 GraphicsPath.AddString - System.ArgumentException: Parameter is not valid. GraphicsPath.AddString System.ArgumentException:参数无效。 在C#中 - System.ArgumentException: Parameter is not valid. in C# 计时器中graphics.DrawLine上的“ System.ArgumentException参数无效” - 'System.ArgumentException parameter is not valid' at graphics.DrawLine in a timer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM