首页 > Windows开发 > 详细

C# Image与Base64编码互转函数

时间:2016-11-24 06:43:06      阅读:160      评论:0      收藏:0      [点我收藏+]
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 = 0;
        ms.Read(arr, 0, (int)ms.Length);
        ms.Close();
        strbaser64 = Convert.ToBase64String(arr);
    }
    catch (Exception)
    {
        throw new Exception("Something wrong during convert!");
    }
    return strbaser64;
}

 

C# Image与Base64编码互转函数

原文:http://www.cnblogs.com/testsec/p/6095710.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!