zoukankan      html  css  js  c++  java
  • C# 发送HttpWebRequest获得网络图片的大小、尺寸

    可以通过HttpWebRequest的方式发送一个网络图片的请求,再通过HttpWebResponse接收返回的数据,分析数据流得到图片的大小以及尺寸,代码如下:

    /// <summary>  
            /// 获取图片的大小和尺寸  
            /// </summary>  
            /// <param name="aPhotoUrl">图片url</param>  
            /// <param name="aSize">图片大小</param>  
            /// <param name="aLength">图片尺寸</param>  
            private void GetPhotoInfo(string aPhotoUrl, ref string aSize, ref string aLength)  
            {  
                try  
                {  
                    Uri mUri = new Uri(aPhotoUrl);  
                    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();  
                    aSize = (mResponse.ContentLength / 1024).ToString() + "KB";  
                    Image mImage = Image.FromStream(mStream);  
                    aLength = mImage.Width.ToString() + "x" + mImage.Height.ToString();  
                    mStream.Close();  
                }  
                catch (Exception e)  
                {  
                    //MessageBox.Show(aPhotoUrl + "获取失败");  
                }  
            }  
    
  • 相关阅读:
    12月10日,小雪
    12月10日,小雪
    BUG
    Twenty Hours
    BUG
    07中华小姐大赛落幕 20岁佳丽曾光夺冠
    Twenty Hours
    jeecg 页面标签规则
    jeecg导入备份
    jeecg查询分页
  • 原文地址:https://www.cnblogs.com/yangdunqin/p/HttpWebRequest.html
Copyright © 2011-2022 走看看