C# 图片和Base64之间的转换

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;
}

posted @ 2016-12-16 13:12  可乐•雪碧•咖啡•茶  阅读(280)  评论(0编辑  收藏  举报