首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#依据图片链接地址获取它的像素宽度和高度

2013-11-13 
C#根据图片链接地址获取它的像素宽度和高度http://ww2.sinaimg.cn/bmiddle/6128e4c9jw1e8w8ckn6taj20np0hs

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

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;    //显示图片
        }
    }
}


[解决办法]

这是什么情况呀???
路径格式不对啊,把\改成\\试试
[解决办法]
 

热点排行