HttpWebRequest对象抓取网页上的图片

用c#的HttpWebRequest对象抓取网页上的图片

没什么实际意义,用c#抓取网上的图片显示在picturebox里,虽然没多大用处,但可以在固定的地址抓取大量验证码下来。代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Collections.Specialized;

 

usingSystem.Threading;

usingSystem.Net;

usingSystem.IO;

 

namespaceGetWebimage

{

   publicpartialclassForm1:Form

    {

       publicForm1()

        {

           InitializeComponent();

        }

       publicvoidgetimages(stringurl)

        {

       try

            {

               HttpWebRequestrequest= (HttpWebRequest)WebRequest.Create(url);

               StreamresponseStream= ((HttpWebResponse)request.GetResponse()).GetResponseStream();

               Imageoriginal=Image.FromStream(responseStream);

               Bitmapmap_bitMap=newBitmap(original);

               this.pictureBox1.Image=map_bitMap;

            }

           catch(System.Exceptione)

            {

            MessageBox.Show("error",e.Message.ToString());

            }

        }

 

       privatevoidpictureBox1_Click(objectsender,EventArgse)

        {

           

        }

       publicvoidgetThefuckingimage()

        {

 

           stringimageUrl="http://img.daqi.com/upload/slidepic/publish/2009-11-19/010_33978371_.jpg";

             getimages(imageUrl);

 

       privatevoidbutton1_Click(objectsender,EventArgse)

        {

           //开个新线程,防止界面假死。

           ThreadthreadGetimage=newThread(newThreadStart(getThefuckingimage));

           threadGetimage.Start();

        }

    }

}

posted @ 2013-03-10 00:30  染血的童话使  阅读(787)  评论(0)    收藏  举报