gpt4 book ai didi

c# - 无法在 Image 类中找到 FromStream

转载 作者:IT王子 更新时间:2023-10-29 04:26:21 24 4
gpt4 key购买 nike

我有以下代码:

Image tmpimg = null;
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
return Image.FromStream(stream);

在我输入 Image. 时的最后一行,FromStream 不在列表中。我能做什么?

最佳答案

使用和所需命名空间的更详细示例。

using System.Net;
using System.IO;
using System.Drawing;

public static Image GetImageFromUrl(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
using (Stream stream = httpWebReponse.GetResponseStream())
{
return Image.FromStream(stream);
}
}
}

关于c# - 无法在 Image 类中找到 FromStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10077219/

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