//把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;
}
}