基本信息
源码名称:批量下载图片
源码大小:3.24M
文件格式:.zip
开发语言:C#
更新时间:2015-01-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 10 元×
微信扫码支付:10 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
批量下载图片
首先从文本文件导入要下载的图片网址(每行一个即可),然后点击开始 即可批量下载,图片下载至bin目录下的【路径】文件夹了
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.IO; using System.Net; using System.Windows.Forms; namespace imagesclq { public class frmimages : Form { private int zgo = 0; private int cg = 0; private int sb = 0; private ArrayList sbd = new ArrayList(); private ArrayList listdb = new ArrayList(); private IContainer components = null; private Button button1; private Button button2; private FolderBrowserDialog fldefie; private Label lbllu; private Button button3; private Label lbljianlu; private OpenFileDialog ofiledbs; private TextBox txtshijia; private Timer timer1; private Label label1; private Label label2; private TextBox txtnancom; private Label lbltup; private Button button4; private CheckBox cboissf; private TabControl tabControl1; private TabPage tabPage1; private TabPage tabPage2; private Label lblsb; private Label lblcg; private Label lblzg; private TextBox txtzt; private RichTextBox rtbsbd; private Button button5; public frmimages() { this.InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.timer1.Enabled = true; this.timer1.Start(); if (this.txtshijia.Text != "") { this.timer1.Interval = Convert.ToInt32(this.txtshijia.Text); } if (this.txtnancom.Text == "") { MessageBox.Show("请选择后缀"); this.timer1.Stop(); } } private void geturl() { try { if (this.zgo >= this.listdb.Count) { this.timer1.Stop(); if (this.cboissf.Checked) { Application.Exit(); } MessageBox.Show("下载完毕"); this.listdb.Clear(); } else { string url = this.listdb[this.zgo].ToString(); this.txtzt.Text = this.listdb[this.zgo].ToString(); string wjian = url.Substring(url.IndexOf(this.txtnancom.Text) this.txtnancom.Text.Length); string lujian = wjian.Remove(wjian.LastIndexOf("/")).Replace("/", "\\"); string zgliu = this.lbllu.Text "/" lujian; string filenames = url.Substring(url.LastIndexOf("/")); Directory.CreateDirectory(zgliu); WebClient mywebclient = new WebClient(); mywebclient.DownloadFile(url, zgliu filenames); this.zgo ; this.cg ; this.lblcg.Text = "成功:" this.cg.ToString() "个"; } } catch (Exception) { this.sb ; this.sbd.Add(this.txtzt.Text); RichTextBox richTextBox = this.rtbsbd; richTextBox.Text = richTextBox.Text this.txtzt.Text "\r\n"; this.lblsb.Text = "失败:" this.sb.ToString() "个"; this.zgo ; } } private void button2_Click(object sender, EventArgs e) { if (DialogResult.OK == this.fldefie.ShowDialog()) { this.lbllu.Text = this.fldefie.SelectedPath; } } private void button3_Click(object sender, EventArgs e) { if (DialogResult.OK == this.ofiledbs.ShowDialog()) { this.lbljianlu.Text = this.ofiledbs.FileName; try { FileStream aFile = new FileStream(this.lbljianlu.Text, FileMode.Open); StreamReader sr = new StreamReader(aFile); string stlianj2 = ""; while ((stlianj2 = sr.ReadLine()) != null) { this.listdb.Add(stlianj2); } MessageBox.Show("导入链接成功"); this.lblzg.Text = "总共:" this.listdb.Count.ToString(); sr.Close(); aFile.Close(); } catch (Exception) { MessageBox.Show("导入链接失败"); } } } private void txtshijia_TextChanged(object sender, EventArgs e) { } private void timer1_Tick(object sender, EventArgs e) { this.geturl(); } private void fldefie_HelpRequest(object sender, EventArgs e) { } private void frmimages_Load(object sender, EventArgs e) { string ds = DateTime.Now.ToString("yyyyMMdd"); double dd = Convert.ToDouble(ds); //if (dd > 20150801.0) //{ // MessageBox.Show("软件过期了"); // Application.Exit(); //} MessageBox.Show("欢迎使用!"); } private void button4_Click(object sender, EventArgs e) { Application.Exit(); } private void button5_Click(object sender, EventArgs e) { this.zgo = 0; this.cg = 0; this.sb = 0; this.listdb.Clear(); if (this.sbd.Count > 0) { for (int i = 0; i < this.sbd.Count; i ) { this.listdb.Add(this.sbd[i].ToString()); } } this.timer1.Enabled = true; this.timer1.Start(); this.sbd.Clear(); } protected override void Dispose(bool disposing) { if (disposing && this.components != null) { this.components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.fldefie = new System.Windows.Forms.FolderBrowserDialog(); this.lbllu = new System.Windows.Forms.Label(); this.button3 = new System.Windows.Forms.Button(); this.lbljianlu = new System.Windows.Forms.Label(); this.ofiledbs = new System.Windows.Forms.OpenFileDialog(); this.txtshijia = new System.Windows.Forms.TextBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.txtnancom = new System.Windows.Forms.TextBox(); this.lbltup = new System.Windows.Forms.Label(); this.button4 = new System.Windows.Forms.Button(); this.cboissf = new System.Windows.Forms.CheckBox(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.lblzg = new System.Windows.Forms.Label(); this.lblsb = new System.Windows.Forms.Label(); this.lblcg = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.rtbsbd = new System.Windows.Forms.RichTextBox(); this.txtzt = new System.Windows.Forms.TextBox(); this.button5 = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 91); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(136, 83); this.button1.TabIndex = 0; this.button1.Text = "开始"; this.button1.UseVisualStyleBackColor = true; // // button2 // this.button2.Location = new System.Drawing.Point(21, 370); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 65); this.button2.TabIndex = 1; this.button2.Text = "保存路径"; this.button2.UseVisualStyleBackColor = true; // // lbllu // this.lbllu.AutoSize = true; this.lbllu.Location = new System.Drawing.Point(119, 410); this.lbllu.Name = "lbllu"; this.lbllu.Size = new System.Drawing.Size(29, 12); this.lbllu.TabIndex = 2; this.lbllu.Text = "路径"; // // button3 // this.button3.Location = new System.Drawing.Point(21, 300); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 44); this.button3.TabIndex = 3; this.button3.Text = "导入文件"; this.button3.UseVisualStyleBackColor = true; // // lbljianlu // this.lbljianlu.AutoSize = true; this.lbljianlu.Location = new System.Drawing.Point(115, 316); this.lbljianlu.Name = "lbljianlu"; this.lbljianlu.Size = new System.Drawing.Size(77, 12); this.lbljianlu.TabIndex = 4; this.lbljianlu.Text = "图片链接路径"; // // ofiledbs // this.ofiledbs.FileName = "openFileDialog1"; // // txtshijia // this.txtshijia.Location = new System.Drawing.Point(65, 62); this.txtshijia.Name = "txtshijia"; this.txtshijia.Size = new System.Drawing.Size(64, 21); this.txtshijia.TabIndex = 5; this.txtshijia.Text = "1"; // // timer1 // this.timer1.Interval = 4500; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(19, 64); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(41, 12); this.label1.TabIndex = 6; this.label1.Text = "线程:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(135, 65); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(83, 12); this.label2.TabIndex = 7; this.label2.Text = "网址后缀.com:"; // // txtnancom // this.txtnancom.Location = new System.Drawing.Point(224, 59); this.txtnancom.Name = "txtnancom"; this.txtnancom.Size = new System.Drawing.Size(70, 21); this.txtnancom.TabIndex = 8; this.txtnancom.Text = "com"; // // lbltup // this.lbltup.AutoSize = true; this.lbltup.Location = new System.Drawing.Point(19, 20); this.lbltup.Name = "lbltup"; this.lbltup.Size = new System.Drawing.Size(95, 12); this.lbltup.TabIndex = 9; this.lbltup.Text = "正在下载的图片:"; // // button4 // this.button4.Location = new System.Drawing.Point(21, 212); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 66); this.button4.TabIndex = 10; this.button4.Text = "退出"; this.button4.UseVisualStyleBackColor = true; // // cboissf // this.cboissf.AutoSize = true; this.cboissf.Location = new System.Drawing.Point(21, 190); this.cboissf.Name = "cboissf"; this.cboissf.Size = new System.Drawing.Size(96, 16); this.cboissf.TabIndex = 11; this.cboissf.Text = "是否发完退出"; this.cboissf.UseVisualStyleBackColor = true; // // tabControl1 // this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(171, 91); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(541, 187); this.tabControl1.TabIndex = 12; // // tabPage1 // this.tabPage1.Controls.Add(this.lblzg); this.tabPage1.Controls.Add(this.lblsb); this.tabPage1.Controls.Add(this.lblcg); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.tabPage1.Size = new System.Drawing.Size(533, 161); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "状态"; this.tabPage1.UseVisualStyleBackColor = true; // // lblzg // this.lblzg.AutoSize = true; this.lblzg.Location = new System.Drawing.Point(22, 33); this.lblzg.Name = "lblzg"; this.lblzg.Size = new System.Drawing.Size(53, 12); this.lblzg.TabIndex = 2; this.lblzg.Text = "总共多少"; // // lblsb // this.lblsb.AutoSize = true; this.lblsb.Location = new System.Drawing.Point(22, 116); this.lblsb.Name = "lblsb"; this.lblsb.Size = new System.Drawing.Size(29, 12); this.lblsb.TabIndex = 1; this.lblsb.Text = "失败"; // // lblcg // this.lblcg.AutoSize = true; this.lblcg.Location = new System.Drawing.Point(22, 80); this.lblcg.Name = "lblcg"; this.lblcg.Size = new System.Drawing.Size(29, 12); this.lblcg.TabIndex = 0; this.lblcg.Text = "成功"; // // tabPage2 // this.tabPage2.Controls.Add(this.rtbsbd); this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); this.tabPage2.Size = new System.Drawing.Size(533, 161); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "失败的"; this.tabPage2.UseVisualStyleBackColor = true; // // rtbsbd // this.rtbsbd.Location = new System.Drawing.Point(6, 10); this.rtbsbd.Name = "rtbsbd"; this.rtbsbd.Size = new System.Drawing.Size(521, 128); this.rtbsbd.TabIndex = 0; this.rtbsbd.Text = ""; // // txtzt // this.txtzt.Location = new System.Drawing.Point(118, 17); this.txtzt.Name = "txtzt"; this.txtzt.Size = new System.Drawing.Size(628, 21); this.txtzt.TabIndex = 13; // // button5 // this.button5.Location = new System.Drawing.Point(302, 84); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(388, 23); this.button5.TabIndex = 14; this.button5.Text = "清空历史采集失败的"; this.button5.UseVisualStyleBackColor = true; // // frmimages // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(758, 449); this.Controls.Add(this.button5); this.Controls.Add(this.txtzt); this.Controls.Add(this.tabControl1); this.Controls.Add(this.cboissf); this.Controls.Add(this.button4); this.Controls.Add(this.lbltup); this.Controls.Add(this.txtnancom); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.txtshijia); this.Controls.Add(this.lbljianlu); this.Controls.Add(this.button3); this.Controls.Add(this.lbllu); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.MaximizeBox = false; this.Name = "frmimages"; this.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultBounds; this.Text = "8.8星辰图片批量下载:QQ 1749408006"; this.tabControl1.ResumeLayout(false); this.tabPage1.ResumeLayout(false); this.tabPage1.PerformLayout(); this.tabPage2.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); } } }