1
이것은 사용하는 기능으로, 하드 디스크의 웹 사이트에서 가져온 링크에 이미지를 저장하고 싶습니다.이미지를 하드 디스크에 저장하려고하면 오류가 발생합니다. URI 형식은 지원되지 않습니다.
public void GetAllImages()
{
// Bing Image Result for Cat, First Page
string url = "http://www.bing.com/images/search?q=cat&go=&form=QB&qs=n";
// For speed of dev, I use a WebClient
WebClient client = new WebClient();
string html = client.DownloadString(url);
// Load the Html into the agility pack
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
// Now, using LINQ to get all Images
/*List<HtmlNode> imageNodes = null;
imageNodes = (from HtmlNode node in doc.DocumentNode.SelectNodes("//img")
where node.Name == "img"
&& node.Attributes["class"] != null
&& node.Attributes["class"].Value.StartsWith("sg_t")
select node).ToList();*/
var imageLinks = doc.DocumentNode.Descendants("img")
.Where(n => n.Attributes["class"].Value == "sg_t")
.Select(n => HttpUtility.ParseQueryString(n.Attributes["src"].Value["amp;url"])
.ToList();
foreach (string node in imageLinks)
{
y++;
//Console.WriteLine(node.Attributes["src"].Value);
richTextBox1.Text += node + Environment.NewLine;
Bitmap bmp = new Bitmap(node);
bmp.Save(@"d:\test\" + y.ToString("D6") + ".jpg");
}
}
foreach의 맨 아래에 비트 맵을 사용하지만 오류가 발생합니다. 왜 ?
인쇄를 노드 문자열을 비트 맵에 전달을 확인하려면 ctor. 나는 URL (이미지의 src 속성에서)이라고 생각합니다. Bitmap ctor는 파일 이름이 파일을로드 할 것으로 기대하지만 URI에 지원되지 않습니다 (예외로 작성). 웹 요청을 사용하여 원격 URL에서 이미지를 다운로드해야합니다. –