日期:2014-05-18 浏览次数:20769 次
#region "字符串图片转换" /// <summary> /// 将Base64转成图片 /// </summary> /// <param name="str">Base64字符串</param> /// <returns>图片</returns> /// <remarks></remarks> public static Image StrToImage(string str) { if (str.Length == 0) { return null; } byte[] bs = Convert.FromBase64String(str); System.IO.Stream stream = new System.IO.MemoryStream(bs); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(stream); return bmp; } /// <summary> /// 将图片转成Base64字符串 /// </summary> /// <param name="image">图片</param> /// <returns>Base64字符串</returns> /// <remarks></remarks> public static string ImageToStr(Image image) { if (image == null) { return ""; } byte[] resByte = null; dynamic MemoryStream = new System.IO.MemoryStream(); image.Save(MemoryStream, System.Drawing.Imaging.ImageFormat.Png); resByte = MemoryStream.GetBuffer(); //取内存流数据 return Convert.ToBase64String(resByte); } #endregion