当前位置:   article > 正文

html点击图片获取信息,根据URL 返回HTML 根据URL--获取图片信息

html 选中图片 获取图片信息

///

/// 根据URL 返回HTML

///

private List GetHtmlByUrl(string

Url)

{

WebClient client = new WebClient();

byte[] page = client.DownloadData(Url);

string content =

System.Text.Encoding.UTF8.GetString(page);

List

_list = GetImgUrlByHtmlText(content);

return _list;

}

/---------------------根据URL--获取图片信息--------------/

//后缀名

string _suffix = _imgurls[i].Substring(_imgurls[i].Length - 4);

//图片文件名

string _imageInputTitle = "云鼎宝贝" +

DateTime.Now.ToString("yyyyMMddhhmmss" + i) + _suffix;

System.Net.HttpWebRequest webRequest =

(System.Net.HttpWebRequest)System.Net.WebRequest.Create(_imgurls[i]);

webRequest.Method = "GET";

System.Net.HttpWebResponse webResponse =

(System.Net.HttpWebResponse)webRequest.GetResponse();

//获取图片保存到流

System.IO.Stream _stream = webResponse.GetResponseStream();

//保存到图片

System.Drawing.Image _image =

System.Drawing.Image.FromStream(_stream);

// int _picwidth = _imgWidth.Length <= 0 ?

_image.Width : Convert.ToInt32(_imgWidth);

// int

_picheight = _imgHeight.Length <= 0 ? _image.Height :

Convert.ToInt32(_imgHeight);

//根据参数形成缩略图

//_image =

_image.GetThumbnailImage(_image.Width, _image.Height, null, IntPtr.Zero);

//实例化MemoryStream

System.IO.MemoryStream _ImageMem = new System.IO.MemoryStream();

//实例化图片格式

//ImageFormat _imgFormat = new

ImageFormat(new Guid());

//根据图片后缀名判断类型.

// if

(_suffix.ToLower().Equals(".jpg")) _imgFormat = ImageFormat.Jpeg;

// if (_suffix.ToLower().Equals(".png")) _imgFormat =

ImageFormat.Png;

// if (_suffix.ToLower().Equals(".gif"))

_imgFormat = ImageFormat.Gif;

//保存

_image.Save(_ImageMem, _image.RawFormat);

//转换为字节流

byte[] _ImageBytes = _ImageMem.GetBuffer();

//释放资源

_image.Dispose();

//关闭流

_stream.Close();

原文:http://www.cnblogs.com/mingxuantongxue/p/3680866.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/110421
推荐阅读
相关标签
  

闽ICP备14008679号