zoukankan      html  css  js  c++  java
  • 网络图片、CSV文件请求读取转DataTable

    1、读取网络图片,获取图片宽高

    string path = “http://xxx.jpg” //图片路径;

    Uri mUri = new Uri(path);http://xxx.jpg
    HttpWebRequest mRequest = (HttpWebRequest)WebRequest.Create(mUri);
    mRequest.Method = "GET";
    mRequest.Timeout = 200;
    mRequest.ContentType = "text/html;charset=utf-8";
    HttpWebResponse mResponse = (HttpWebResponse)mRequest.GetResponse();
    Stream mStream = mResponse.GetResponseStream();
    string aSize = (mResponse.ContentLength / 1024).ToString() + "KB";
    Image mImage = Image.FromStream(mStream);
    string aLength = mImage.Width.ToString() + "x" + mImage.Height.ToString();

    2、读取网络CSV文件,数据转为DataTable处理

    Uri mUri = new Uri(“http://xxx.csv");
    HttpWebRequest mRequest = (HttpWebRequest)WebRequest.Create(mUri);
    mRequest.Method = "GET";
    mRequest.Timeout = 20000;
    mRequest.ContentType = "text/html;charset=utf-8";
    HttpWebResponse mResponse = (HttpWebResponse)mRequest.GetResponse();
    Stream mStream = mResponse.GetResponseStream();

    StreamReader sr = new StreamReader(mStream);
    string strTitle = "x,y,value";
    string[] strColumTitle = strTitle.Split(','); //CVS 文件默认以逗号隔开
    for (int i = 0; i < strColumTitle.Length; i++)
    {
    dt.Columns.Add(strColumTitle[i]);
    }
    while (!sr.EndOfStream)
    {
    string strTest = sr.ReadLine().Trim('');
    if (!string.IsNullOrWhiteSpace(strTest))
    {
    DataRow dr = dt.NewRow();
    if (dt.Columns.Count == 1)
    {
    dr[0] = strTest;
    }
    else
    {
    string[] strTestAttribute = strTest.Split(',');
    for (int i = 0; i < strColumTitle.Length; i++)
    {
    dr[strColumTitle[i]] = strTestAttribute[i];
    }
    }
    dt.Rows.Add(dr);
    }
    sr.Close();

  • 相关阅读:
    vue2.0是不支持通过下标来更改数组的,无法做到响应式
    C# 深拷贝 Bitmap对象示例
    vscode终端中文乱码
    TkbmMemTable使用总结
    openssl 证书概念介绍
    openssl源码介绍
    python变量赋值特性
    openssl安装
    github开源协议选择
    NLP 多分类神经网络
  • 原文地址:https://www.cnblogs.com/tl1025/p/15152534.html
Copyright © 2011-2022 走看看