图片流转为字符串

using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


Image TestImage = Image.FromFile(@"H:\Image文件\复件 000198770.jpg");//截入图片 MemoryStream ChangeBeforeMS=new MemoryStream();//定义一个内存流 TestImage.Save(ChangeBeforeMS,System.Drawing.Imaging.ImageFormat.Jpeg);//将图片的内容保存到内存流上面 byte[] ChangeBeforImageBytes = ChangeBeforeMS.ToArray() ;//将内存流保存到字节数组中 //string ImageStr = Encoding.ASCII.GetString(ChangeBeforImageBytes);//将字节数组拼成字符串 //byte[] ChangeAfterImageBytes = Encoding.ASCII.GetBytes(ImageStr);//再将字符串分拆成字节数组 string ImageStr = Convert.ToBase64String( ChangeBeforImageBytes);//将字节数组拼成字符串 byte[] ChangeAfterImageBytes = Convert.FromBase64String (ImageStr);//再将字符串分拆成字节数组 MemoryStream ChangeAfterMS = new MemoryStream(ChangeAfterImageBytes);//将字节数组保存到新的内存流上 TestImage = Image.FromStream(ChangeAfterMS);//将内存流保存成一张图片






HttpWebRequest request = WebRequest.Create(imgurl) as HttpWebRequest;

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

 

Stream myResponseStream = response.GetResponseStream();
Image TestImage = Image.FromStream(myResponseStream);
MemoryStream ChangeBeforeMS = new MemoryStream();//定义一个内存流
TestImage.Save(ChangeBeforeMS, System.Drawing.Imaging.ImageFormat.Jpeg);//将图片的内容保存到内存流上面
byte[] ChangeBeforImageBytes = ChangeBeforeMS.ToArray();//将内存流保存到字节数组中
//string ImageStr = Encoding.ASCII.GetString(ChangeBeforImageBytes);//将字节数组拼成字符串
//byte[] ChangeAfterImageBytes = Encoding.ASCII.GetBytes(ImageStr);//再将字符串分拆成字节数组
__ImgStream = Convert.ToBase64String(ChangeBeforImageBytes);//将字节数组拼成字符串







 
posted @ 2016-06-28 10:11  孟小白  阅读(1271)  评论(0编辑  收藏  举报