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.Net;
using System.IO;
namespace Faron_WinFormApp
{
public partial class WebClient_DownPic : Form
{
private string picUrl;
public WebClient_DownPic()
{
InitializeComponent();
}
private void DownLoadPic(string url)
{
string picName = url.Substring(url.LastIndexOf("/")+1);
Uri uri = new Uri(url);
WebClient wc = new WebClient();
try
{
//Bitmap bmp = new Bitmap(wc.OpenRead(uri));
wc.DownloadFile(uri, Directory.GetCurrentDirectory() + "/" + picName);
MessageBox.Show("成功下载图片" + picName);
}
catch (Exception ex)
{
}
finally
{
if (wc != null)
wc.Dispose();
}
}
private void button1_Click(object sender, EventArgs e)
{
picUrl = this.textBox1.Text;
if (picUrl == string.Empty)
MessageBox.Show("请输入图片地址");
else
DownLoadPic(picUrl);
}
}
}
WebClient下载图片示例
最新推荐文章于 2023-07-12 18:21:33 发布