图片和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;
}

上一篇:fiddler4微信抓包教程


下一篇:【PAT B1059】C语言竞赛 (20 分)