C# Image与Base64编码互转函数

public Bitmap GetImageFromBase64(string base64string)
{
byte[] b = Convert.FromBase64String(base64string);
MemoryStream ms = new MemoryStream(b);
Bitmap bitmap = new Bitmap(ms);
return bitmap;
}
public string GetBase64FromImage(string imagefile)
{
string strbaser64 = "";
try
{
Bitmap bmp = new Bitmap(imagefile);
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
ms.Position = ;
ms.Read(arr, , (int)ms.Length);
ms.Close();
strbaser64 = Convert.ToBase64String(arr);
}
catch (Exception)
{
throw new Exception("Something wrong during convert!");
}
return strbaser64;
}
上一篇:2016百度之星 初赛2A ABEF


下一篇:Python——列表、元祖、字典、集合的基本操作