C# url获取图片流转字符串
2021-03-27 08:27
标签:ima raw turn 获得 path close adb temp request //本地url获取图片流转字符串 return str; C# url获取图片流转字符串 标签:ima raw turn 获得 path close adb temp request 原文地址:https://www.cnblogs.com/TianXiaoLu/p/9358707.html
//http url获取图片流转字符串
//string url = serverUrl.TrimEnd(‘/‘) + PUrl;
//WebRequest request = WebRequest.Create(url);
//WebResponse response = request.GetResponse();
//Stream stream = response.GetResponseStream();
//byte[] byteFile = null;
//List
//int temp = stream.ReadByte();
//while (temp != -1)
//{
// bytes.Add((byte)temp);
// temp = stream.ReadByte();
//}
//byteFile = bytes.ToArray();
//string str = Convert.ToBase64String(byteFile);
//response.Close();
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);