Skip to content

Instantly share code, notes, and snippets.

@FrankFan
Created April 21, 2014 01:33
Show Gist options
  • Save FrankFan/11129849 to your computer and use it in GitHub Desktop.
Save FrankFan/11129849 to your computer and use it in GitHub Desktop.
下载图片
/// <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