C# url获取图片流转字符串

2021-03-27 08:27

阅读:316

标签:ima   raw   turn   获得   path   close   adb   temp   request   


//http url获取图片流转字符串
//string url = serverUrl.TrimEnd(‘/‘) + PUrl;
//WebRequest request = WebRequest.Create(url);
//WebResponse response = request.GetResponse();
//Stream stream = response.GetResponseStream();
//byte[] byteFile = null;
//List bytes = new 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();

//本地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;

C# url获取图片流转字符串

标签:ima   raw   turn   获得   path   close   adb   temp   request   

原文地址:https://www.cnblogs.com/TianXiaoLu/p/9358707.html


评论


亲,登录后才可以留言!