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 + "获取失败");  
                }  
            }  
    
  • 相关阅读:
    Thinkphp的import使用方法
    bug1
    setTimeout关于函数名做参数的问题
    ubuntu-12.04.5安装cacti笔记
    第七周作业
    第六周作业
    第五周作业
    第四周编程总结
    2019年春季学期第三周作业
    第二周编程总结
  • 原文地址:https://www.cnblogs.com/yangdunqin/p/HttpWebRequest.html
Copyright © 2011-2022 走看看