/// <summary>
/// 根据网络路径把文件保存成byte[],保存到本地
/// </summary>
/// <param name="filePath"></param>
public byte[] UrlToByte(string filePath)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(filePath);
req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
StreamReader responseStream = new StreamReader(wr.GetResponseStream(), Encoding.UTF8);
int length = (int)wr.ContentLength;
byte[] bs = new byte[length];
HttpWebResponse response = wr as HttpWebResponse;
Stream stream = response.GetResponseStream();
//读取到内存
MemoryStream stmMemory = new MemoryStream();
byte[] buffer1 = new byte[length];
int i;
while ((i = stream.Read(buffer1, 0, buffer1.Length)) > 0)
{
stmMemory.Write(buffer1, 0, i);
}
byte[] arraryByte = st
根据网络路径(http/https开头)图片转换成byte[]保存
最新推荐文章于 2024-03-18 10:42:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)