我在以下代码中遇到异常:
(System.IO.MemoryStream) Stream stream = new MemoryStream(fcr.FileContents);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
Run Code Online (Sandbox Code Playgroud)
我将它包装在 Try/Catch 中,并且在第二行抛出异常:Message = "Parameter is not valid."
我检查了变量的内容stream。这就是错误所在。展开 的内容stream,我发现:
Read.TimeOut: 'stream.Read.TimeOut'threw an exception of type
'System.InvalidOperationException'
Write.TimeOut: 'stream.Write.TimeOut' thew an exception of type
'System.InvalidOperationException'
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
我该如何解决?
using (Stream stream = new MemoryStream(fcr.FileContents))
{
System.Drawing.Image img = System.Drawing.Image.FromStream(stream, true, true);
Run Code Online (Sandbox Code Playgroud)在这里继续崩溃,参数无效。对象流仍然具有读取和写入超时消息。
使用前需要改变位置。
using (Stream stream = new MemoryStream(fcr.FileContents))
{
stream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(stream, true, true);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8282 次 |
| 最近记录: |