如何获取网页中图片的URL!! 急!!
本人想实现的功能:用鼠标拖动网页上的图片,保存到本地磁盘.
用webclient可以实现指定URL的图片保存到本地,如下:
WebClient myWebClient = new WebClient();
string url = "http://cimg2.163.com/cnews/2007/3/28/200703281401315f88c.gif ";
myWebClient.DownloadFile(url, "d:\\1.gif ");
现在的问题是:如何在鼠标拖动网页上某张图片时获取图片的URL.
我用的是:
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string a;
//a = new e.Data.GetData(DataFormats.FileDrop);
a = ((System.Array)e.Data.GetData(DataFormats.Bitmap)).GetValue(0).ToString();
Bitmap bt = new Bitmap(a);
this.pictureBox1.Image = bt;
}
但,窗体无法接收被拖放的图片.
请高手,指点!!!!!!!
------解决方案--------------------using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace Drag
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnDragEnter(DragEventArgs drgevent)
{
if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
drgevent.Effect = DragDropEffects.Copy;
base.OnDragEnter(drgevent);
}
protected override void OnDragDrop(DragEventArgs drgevent)
{
if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] vFileNames = (string[])drgevent.Data.GetData(
DataFormats.FileDrop);
if (vFileNames.Length > 0)
{
switch (Path.GetExtension(vFileNames[0]).ToLower())
{
case ".bmp ":
case ".gif ":
case ".jpg ":
pictureBox1.Image = Image.FromFile(vFileNames[0]);
break;
}
}
}
base.OnDragDrop(drgevent);
}
}
}