• 网络图片、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();

  • 相关阅读:
    ReLU激活函数:简单之美
    逻辑回归(Logistic Regression)推导
    机器学习之视频推荐
    TensorFlow OOM when allocating tensor with shape[5000,384707]
    工银亚洲账户激活
    微信小程序之多行文本省略号
    关于微信小程序:scroll-view,backgroundTextStyle
    css之box-sizing属性(css3中的新属性)
    css之max-width属性
    css中的display属性之li元素
  • 原文地址:https://www.cnblogs.com/tl1025/p/15152534.html
Copyright © 2020-2023  润新知