我用 HTMLAgilityPack 得到一张图片,然后我想将它作为字节加载,这样我就可以将它保存在数据库中。
byte[] bIMG = File.ReadAllBytes(doc.DocumentNode.SelectSingleNode("//img[@class='image']").Attributes["src"].Value);
但是它说 URI 格式不受支持。
我还能怎么做呢?
编辑:doc.DocumentNode.SelectSingleNode("//img[@class='image']").Attributes["src"].Value 给出链接
最佳答案
System.IO.File
类无法读取 Web URI - 您可以为此使用 WebClient:
byte[] imageAsByteArray;
using(var webClient = new WebClient())
{
imageAsByteArray = webClient.DownloadData("uri src");
}
关于c# - 从 url 加载图像并将其保存为字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14116097/