首页 > 其他 > 详细

字符串和图片转换

时间:2014-10-30 16:45:23      阅读:230      评论:0      收藏:0      [点我收藏+]

//把Image转换成字符串
string ImageToStr(Image img)
{
using (MemoryStream msStream=new MemoryStream())
{
BinaryFormatter sf=new BinaryFormatter();
sf.Serialize(msStream,img);
byte[] bytes = msStream.ToArray();
return Convert.ToBase64String(bytes);
}
}

 

//把字符串转换成图片

 

Image StrToImage(string str)

{
byte[] buffer = Convert.FromBase64String(str);
using (MemoryStream ms=new MemoryStream())
{
ms.Write(buffer,0,buffer.Length);
ms.Position = 0;
BinaryFormatter bf=new BinaryFormatter();
Image img= bf.Deserialize(ms) as Image;
return img;
}
}

字符串和图片转换

原文:http://www.cnblogs.com/puweibuqi/p/4063041.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!