C#图片的Base64编码和解码

来源:互联网 发布:网络大电影 兴影网 编辑:程序博客网 时间:2024/04/28 15:38
图片的Base64编码:

            System.IO.MemoryStream m = new System.IO.MemoryStream();
            System.Drawing.Bitmap bp = new System.Drawing.Bitmap(@“c:/demo.GIF”);
            bp.Save(m, System.Drawing.Imaging.ImageFormat.Gif);
            byte[]b= m.GetBuffer();
            string base64string=Convert.ToBase64String(b);

Base64字符串解码:

                byte[] bt = Convert.FromBase64String(base64string);
                System.IO.MemoryStream stream = new System.IO.MemoryStream(bt);
                Bitmap bitmap = new Bitmap(stream);  
0 0
原创粉丝点击