|
在使用用例获取图片时,总是报错,不知道是什么问题- private void bt2_Click(object sender, EventArgs e)
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = "http://www.sufeinet.com/",//URL 必需项
- Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
- //Encoding = Encoding.Default,
- ResultType = ResultType.Byte
- };
- //得到HTML代码
- HttpResult result = http.GetHtml(item);
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- //表示访问成功,具体的大家就参考HttpStatusCode类
- }
- //表示StatusCode的文字说明与描述
- string statusCodeDescription = result.StatusDescription;
- //把得到的Byte转成图片
- Image img = byteArrayToImage(result.ResultByte);
- }
- private Image byteArrayToImage(byte[] Bytes)
- {
- using (MemoryStream ms = new MemoryStream(Bytes))
- {
- Image outputImg = Image.FromStream(ms);
- return outputImg;
- }
- }
复制代码 |
|