http://ww2.sinaimg.cn/bmiddle/6128e4c9jw1e8w8ckn6taj20np0hs0uw.jpg
我要根据这个图片链接地址用winfrom获取到它的像素宽度和高度,怎么获取呀?
代码怎么写呀C#winfrom图片像素

解决方案 »

  1.   

    我是用winform写的,一个picturebox,一个button,两个label,两个textbox。
    using System;
    using System.Drawing;
    using System.Net;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            //private static string url = "http://www3.clustrmaps.com/stats/maps-layer/958000/958172/www.cnblogs.com-sun8134--thumb-dots.png";
            private static string url = "http://ww2.sinaimg.cn/bmiddle/6128e4c9jw1e8w8ckn6taj20np0hs0uw.jpg";
            private static string filepath = "c:\\pic.bmp";
            public Form1()
            {
                InitializeComponent();
                pictureBox1.BackColor = Color.Black;
            }        private void button1_Click(object sender, EventArgs e)
            {
                WebClient mywebclient = new WebClient();
                mywebclient.DownloadFile(url, filepath);
                Bitmap bmp = new Bitmap(filepath);
                int w_bmp = bmp.Width;
                int h_bmp = bmp.Height;
                textBox1.Text = Convert.ToString(w_bmp);
                textBox2.Text = Convert.ToString(h_bmp);
                pictureBox1.Image = bmp;
            }
        }
    }
    我是先下载图片,在生成实例bmp,获取bmp的宽度和高度。
      

  2.   

    private static string filepath = "c:\\pic.bmp";
    这里指的是下载图片到c盘文件夹并取名为pic.bmp么???
      

  3.   

    好吧!我加注释!using System;
    using System.Drawing;
    using System.Net;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            //private static string url = "http://www3.clustrmaps.com/stats/maps-layer/958000/958172/www.cnblogs.com-sun8134--thumb-dots.png";
            private static string url = "http://ww2.sinaimg.cn/bmiddle/6128e4c9jw1e8w8ckn6taj20np0hs0uw.jpg";       //网页图片路径
            private static string filepath = "c:\\pic.bmp";         //指定下载到本地的图片路径和扩展名
            public Form1()
            {
                InitializeComponent();
                pictureBox1.BackColor = Color.Black;        //初始化picturebox1控件的背景为黑色
            }        //button1的按钮点击事件
            private void button1_Click(object sender, EventArgs e)
            {
                WebClient mywebclient = new WebClient();    //url连接新实例
                mywebclient.DownloadFile(url, filepath);    //下载图片到指定地址
                Bitmap bmp = new Bitmap(filepath);          //根据地址生成新bitmap实例bmp
                int w_bmp = bmp.Width;      //bmp宽度
                int h_bmp = bmp.Height;     //bmp高度
                textBox1.Text = Convert.ToString(w_bmp);    //显示宽度
                textBox2.Text = Convert.ToString(h_bmp);    //显示高度
                pictureBox1.Image = bmp;    //显示图片
            }
        }
    }
      

  4.   


            /// <summary>  
            /// 获取图片的大小和尺寸  
            /// </summary>  
            /// <param name="aPhotoUrl">图片url</param>  
            /// <param name="iWidth">图片宽度</param>  
            /// <param name="iHeight">图片高度</param>  
            private void GetPhotoInfo(string aPhotoUrl, ref int iWidth, ref int iHeight)
            {
                try
                {
                    Uri mUri = new Uri(aPhotoUrl);
                    HttpWebRequest mRequest = (HttpWebRequest)WebRequest.Create(mUri);
                    mRequest.Method = "GET";
                    mRequest.Timeout = 200;
                    HttpWebResponse mResponse = (HttpWebResponse)mRequest.GetResponse();
                    Stream mStream = mResponse.GetResponseStream();
                    Image mImage = Image.FromStream(mStream);                iWidth = mImage.Width;
                    iHeight = mImage.Height;
                    mStream.Close();
                }
                catch (Exception e)
                {
                    //MessageBox.Show(aPhotoUrl + "获取失败");  
                }
            } 
      

  5.   

    我添加了using System.Net;这个引用了怎么还是