//http url获取图片流转字符串
//string url = serverUrl.TrimEnd(‘/‘) + PUrl;
//WebRequest request = WebRequest.Create(url);
//WebResponse response = request.GetResponse();
//Stream stream = response.GetResponseStream();
//byte[] byteFile = null;
//List<byte> bytes = new List<byte>();
//int temp = stream.ReadByte();
//while (temp != -1)
//{
// bytes.Add((byte)temp);
// temp = stream.ReadByte();
//}
//byteFile = bytes.ToArray();
//string str = Convert.ToBase64String(byteFile);
//response.Close();
//本地url获取图片流转字符串
string path = "E:/1.png";
FileStream fs = File.OpenRead(path); //OpenRead
int filelength = 0;
filelength = (int)fs.Length; //获得文件长度
Byte[] image = new Byte[filelength]; //建立一个字节数组
fs.Read(image, 0, filelength); //按字节流读取
System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
fs.Close();
string str = Convert.ToBase64String(image);
return str;
原文地址:https://www.cnblogs.com/TianXiaoLu/p/9358707.html