请大家仔细看题目
实在不想看到答非所问的答案了题目:
知道一个图片的URL地址 例如(http://avatar.profile.csdn.net/4/E/D/2_kevin_cheung.jpg)
然后需要把这个图片转化为我想要的大小加载到一个winform的pictureBox中要求:
1.不要夹杂中间过程(如:下载,修改,加载)
2.所有操作都在内存上进行,不要在硬盘上产生文件
实在不想看到答非所问的答案了题目:
知道一个图片的URL地址 例如(http://avatar.profile.csdn.net/4/E/D/2_kevin_cheung.jpg)
然后需要把这个图片转化为我想要的大小加载到一个winform的pictureBox中要求:
1.不要夹杂中间过程(如:下载,修改,加载)
2.所有操作都在内存上进行,不要在硬盘上产生文件
{
this.pictureBox1.Image= GetWebImage(new Uri("http://avatar.profile.csdn.net/4/E/D/2_kevin_cheung.jpg"), 100, 100);
}
public Image GetWebImage(Uri p_Address, int p_Width, int p_Height)
{
byte[] _ImageByte = new WebClient().DownloadData(p_Address);
Bitmap _Bitmap = new Bitmap(p_Width, p_Height);
Graphics _Graphcis = Graphics.FromImage(_Bitmap);
_Graphcis.DrawImage(Image.FromStream(new MemoryStream(_ImageByte)), 0, 0, p_Width, p_Height);
_Graphcis.Dispose();
return _Bitmap;
}
设置ImageLocation属性就可以了private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.ImageLocation = "http://avatar.profile.csdn.net/4/E/D/2_kevin_cheung.jpg";
//this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
this.pictureBox1.Width = 180;
this.pictureBox1.Height = 200;
}
Bitmap bit2 = new Bitmap(bit1, width, height);