码迷,mamicode.com
首页 > 其他好文 > 详细

图片和Base64之间的转换

时间:2016-12-16 14:38:12      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:public   turn   map   for   new   转换   ret   stream   style   

public static Bitmap GetImageFromBase64String(string strBase)
{
  try
  {
    MemoryStream stream = new MemoryStream(Convert.FromBase64String(strBase));
    Bitmap bitmap = new Bitmap(stream);
    return bitmap;
  }
  catch(Exception ex)
  {
  return null;
  }

}

public static string GetBase64StringFromImage(Image image, ImageFormat imageFormat)
{
  string strRst = string.Empty;
  try
  {
    MemoryStream stream = new MemoryStream();
    image.Save(stream, imageFormat);
    strRst = Convert.ToBase64String(stream.GetBuffer());
  }
  catch (Exception ex)
  {}
return strRst;
}

图片和Base64之间的转换

标签:public   turn   map   for   new   转换   ret   stream   style   

原文地址:http://www.cnblogs.com/SuperMetalMax/p/6186448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!