Created
April 21, 2014 01:33
-
-
Save FrankFan/11129849 to your computer and use it in GitHub Desktop.
下载图片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 根据指定的url下载数据 | |
/// </summary> | |
/// <param name="url">url</param> | |
/// <returns></returns> | |
public byte[] DownloadImg2Bytes(string url) | |
{ | |
WebClient wc = new WebClient(); | |
byte[] bytes; | |
try | |
{ | |
bytes = wc.DownloadData(url); | |
} | |
catch (WebException ex) | |
{ | |
LogHelper.LogError("DownloadImg2Bytes出错了: ex:{0}", ex); | |
bytes = null; | |
} | |
return bytes; | |
} | |
/// <summary> | |
/// 字节流转换成图片 | |
/// </summary> | |
/// <param name="byt">要转换的字节流</param> | |
/// <returns>转换得到的Image对象</returns> | |
public Image BytToImg(byte[] byt) | |
{ | |
MemoryStream ms = new MemoryStream(byt); | |
Image img = Image.FromStream(ms); | |
ms.Close(); | |
return img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment