private void button1_Click(object sender, EventArgs e) { try { var base64 = this.richTextBox1.Text; 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("yyyyMMdd") + ".jpg"; bp.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);//注意保存路径 string pathpdf = pathA + DateTime.Now.ToString("yyyyMMdd") + ".pdf"; } catch (Exception) { throw; } }
标签:MemoryStream,C#,image,base64,Replace,pathA,data,图片 From: https://www.cnblogs.com/lydj/p/17123846.html