如何将data:image 数据流 保存成图片文件?

PCCYC 2018-01-03 04:04:32
各位朋友,请教个问题,我得到了一串data:image/xx格式的数据流,想要保存成它原本的图片文件。
请问在.net中有什么好的内置方法没?非常感谢。
...全文
2329 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
PCCYC 2018-01-04
  • 打赏
  • 举报
回复
非常感谢。!
anliuty 2018-01-03
  • 打赏
  • 举报
回复
像这种代码要怎么写的问题,先问搜索引擎,归纳好搜索关键字,一搜一大堆解决方案,这样能快速解决你的问题
xinbada1985 2018-01-03
  • 打赏
  • 举报
回复
以上是两个之间的互相转换
xinbada1985 2018-01-03
  • 打赏
  • 举报
回复
//base64编码 转为 图片 private void Base64StringToImage(string base64) { try { BitmapImage bmp =new BitmapImage(); byte[] bytes = Convert.FromBase64String(base64); MemoryStream memStream = new MemoryStream(bytes); Bitmap b = new Bitmap(memStream ); b.Save("保存位子"); //MessageBox.Show("转换成功!"); } catch (Exception ex) { MessageBox.Show("Base64StringToImage 转换失败\nException:" + ex.Message); } }
xinbada1985 2018-01-03
  • 打赏
  • 举报
回复
//图片 转为 base64编码的文本 private void ImgToBase64String(string Imagefilename) { try { Bitmap bmp = new Bitmap(Imagefilename); this.pictureBox1.Image = bmp; FileStream fs = new FileStream(Imagefilename + ".txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); 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(); String strbaser64 = Convert.ToBase64String(arr); sw.Write(strbaser64); sw.Close(); fs.Close(); // MessageBox.Show("转换成功!"); } catch (Exception ex) { MessageBox.Show("ImgToBase64String 转换失败\nException:" + ex.Message); } }
  • 打赏
  • 举报
回复
前面哪几个字符串截取掉后,后面的就是完整的base64字符串,转化成byte[],再转成Stream,最后Image.FromStream就好了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧