【发布时间】:2011-07-03 12:44:24
【问题描述】:
我有一个用于谷歌图片搜索的 api,但那个太旧了,在目前的谷歌图片搜索中不起作用,那么有没有最新的谷歌图片搜索 api?
【问题讨论】:
标签: c# .net google-api
我有一个用于谷歌图片搜索的 api,但那个太旧了,在目前的谷歌图片搜索中不起作用,那么有没有最新的谷歌图片搜索 api?
【问题讨论】:
标签: c# .net google-api
C# 5.0 和 WPF (2011) 中的 Google 图片搜索客户端 http://www.codeproject.com/Articles/259621/Google-Image-Search-Client-in-Csharp-5-0-and-WPF
【讨论】:
string imgurl = "https://fun.vin/frank-capra-jr";
var documents = new HtmlWeb().Load(imgurl);
var urls = (documents.DocumentNode.Descendants("img")
.Select(e => e.GetAttributeValue("src", null))
.Where(s => !String.IsNullOrEmpty(s))).ToList();
int c = 0;
foreach(string a in urls)
{
string url = a;
using (WebClient webClient = new WebClient())
{
string imageUrl = url;
//string saveLocation = @"C:\New folder (2)\car\someImage.jpg";
byte[] imageBytes;
HttpWebRequest imageRequest = (HttpWebRequest)WebRequest.Create(imageUrl);
WebResponse imageResponse = imageRequest.GetResponse();
Stream responseStream = imageResponse.GetResponseStream();
using (BinaryReader br = new BinaryReader(responseStream))
{
imageBytes = br.ReadBytes(500000);
br.Close();
}
responseStream.Close();
imageResponse.Close();
int Hight = 0;
int wedht = 0;
Image image = null;
using (MemoryStream stream = new MemoryStream(imageBytes))
{
image = Image.FromStream(stream);
}
ImageFormat ab = image.RawFormat;
string ext = new ImageFormatConverter().ConvertToString(ab);
//if (ImageFormat.Jpeg.Equals(image.RawFormat))
//{
// // JPEG
//}
//else if (ImageFormat.Png.Equals(image.RawFormat))
//{
// // PNG
//}
//else if (ImageFormat.Gif.Equals(image.RawFormat))
//{
// // GIF
//}
Hight = image.Height;
wedht = image.Width;
if (!ImageFormat.Gif.Equals(image.RawFormat))
{
string saveLocation = @"C:\New folder (2)\car\someImage" + c + "." + ext;// + "jpg";
FileStream fs = new FileStream(saveLocation, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
try
{
bw.Write(imageBytes);
c++;
}
finally
{
fs.Close();
bw.Close();
}
}
}
【讨论】: