http://ww2.sinaimg.cn/bmiddle/6128e4c9jw1e8w8ckn6taj20np0hs0uw.jpg
我要根据这个图片链接地址用winfrom获取到它的像素宽度和高度,怎么获取呀?
代码怎么写呀C#winfrom图片像素
我要根据这个图片链接地址用winfrom获取到它的像素宽度和高度,怎么获取呀?
代码怎么写呀C#winfrom图片像素
解决方案 »
- NET 有没有一一映射的类。
- 初学者提问,asp.net的后台代码是在SERVER上还是在Client上运行的?
- 无聊和死掉有什么区别
- 一个似乎不难的算法问题
- 如何写double类型可空的正则表达式,求教!
- 有用过Quick CHM或Visual CHM制作帮助文件的朋友帮个忙啊!!有分
- 请问如何将时间(小时和分钟)绑定到listBox呀?先谢谢您了!
- 如何解决多列信息参照问题,急急!!!!!!!50大分
- XML序列化
- 怪事:sn -k key.snk Failed to generate a strong name key pair -- 该密钥集未被定义。
- 请教高手,C#取一台上海耀华XK3190-a9电子称的重量,我想只要加载窗体控件时,取出磅上重量显示在文本框中,能否给个代码,万分感谢
- WPF,一个集合通常不会实现属性更改通知的吗?
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的宽度和高度。
这里指的是下载图片到c盘文件夹并取名为pic.bmp么???
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; //显示图片
}
}
}
/// <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 + "获取失败");
}
}