gpt4 book ai didi

c# - "Parameter is not valid. At System.Drawing.Bitmap..Ctor (Stream stream)."

转载 作者:行者123 更新时间:2023-12-05 03:15:38 27 4
gpt4 key购买 nike

我收到“Parameter is not valid.at System.Drawing.Bitmap..ctor(Stream stream)” 在我的代码中。

我在我的代码中使用了以下行,

System.Drawing.Bitmap image = new System.Drawing.Bitmap(fileUpload1.PostedFile.InputStream);

我没有发现这段代码有任何问题。

最佳答案

在某些情况下,Bitmap 需要一个seekable 流。尝试:

Bitmap image;
using(var ms = new MemoryStream()) {
fileUpload1.PostedFile.InputStream.CopyTo(ms);
ms.Position = 0;
image = new System.Drawing.Bitmap(ms);
}

但是。我还必须注意,这看起来像 ASP.NET; System.Drawing在 ASP.NET 中不受支持:see here

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. For a supported alternative, see Windows Imaging Components.

关于c# - "Parameter is not valid. At System.Drawing.Bitmap..Ctor (Stream stream).",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747777/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com