Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load image from url save it as byte

I getting one image with HTMLAgilityPack and then I want to load it as byte so I could save it in database.

byte[] bIMG = File.ReadAllBytes(doc.DocumentNode.SelectSingleNode("//img[@class='image']").Attributes["src"].Value);

But it says URI formats are not supported. how else I can do that?

EDIT: doc.DocumentNode.SelectSingleNode("//img[@class='image']").Attributes["src"].Value gives a link

like image 490
a1204773 Avatar asked Dec 26 '22 12:12

a1204773


1 Answers

The System.IO.File class can't read web URIs - you can use the WebClient for this:

byte[] imageAsByteArray;
using(var webClient = new WebClient())
{
    imageAsByteArray = webClient.DownloadData("uri src");
}
like image 164
JerKimball Avatar answered Dec 31 '22 15:12

JerKimball