将base64转为图片

void Base64StringToImage(string imgCode)
        {
            try
            {
                String inputStr = imgCode;
                byte[] arr = Convert.FromBase64String(inputStr);
                MemoryStream ms = new MemoryStream(arr);
                Bitmap bmp = new Bitmap(ms);

                //bmp.Save(txtFileName + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                //bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp);
                //bmp.Save(txtFileName + ".gif", ImageFormat.Gif);
                //bmp.Save(txtFileName + ".png", ImageFormat.Png);
                ms.Close();
                this.pictureBox1.Image = bmp;
                //MessageBox.Show("转换成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Base64StringToImage 转换失败\nException:" + ex.Message);
            }
        }

猜你喜欢

转载自www.cnblogs.com/JerryFly/p/10337530.html