把base64格式还原为图片保存在文件夹里面

把base64格式还原为图片保存在文件夹里面

var base64 =FImage;//图片的base6格式
                base64 = base64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/gif;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
                byte[] bytes = Convert.FromBase64String(base64);
                MemoryStream memStream = new MemoryStream(bytes);
                Image mImage = Image.FromStream(memStream);
                Bitmap bp = new Bitmap(mImage);
                MemoryStream ms = new MemoryStream();
                string pathA = AppDomain.CurrentDomain.BaseDirectory + "PdfRecord\\";
                if (!System.IO.Directory.Exists(pathA))
                { System.IO.Directory.CreateDirectory(pathA); }
                string path = pathA + DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";
                bp.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);//注意保存路径

 

posted @ 2023-08-21 10:00  我的未来方程式i  阅读(604)  评论(0编辑  收藏  举报