C# 下载网页中的图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;

namespace WebPicture
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest req
= (HttpWebRequest)WebRequest.Create("http://img2.cache.netease.com/cnews/2011/3/21/201103210158057258d.jpg");

HttpWebResponse res
= (HttpWebResponse)req.GetResponse();
Stream s
= res.GetResponseStream();

Bitmap bmp
= new Bitmap(s);
pictureBox1.Image
= bmp;
s.Close();
}
}
}

posted @ 2011-03-21 09:20  许明吉博客  阅读(1485)  评论(1编辑  收藏  举报