using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms.Design;
namespace Image
{
public class ImageConvert
{
public static void ShowThumbnail(string oldfile, string newfile, int h, int w)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(oldfile);
System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
int oldh = img.Height;
int oldw = img.Width;
int newh,neww;
double h1 = oldh*1.0/h;
double w1 = oldw*1.0/w;
double f = (h1>w1)? h1:w1;
if(f < 1.0)
{
newh = oldh;
neww = oldw;
}
else
{
newh = (int)(oldh/f);
neww = (int)(oldw/f);
}
System.Drawing.Image myThumbnail = img.GetThumbnailImage(neww, newh, myCallback, IntPtr.Zero);
myThumbnail.Save(newfile, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
myThumbnail.Dispose();
}
private static bool ThumbnailCallback()
{
return false;
}
}
public class FolderDialog : FolderNameEditor
{
FolderNameEditor.FolderBrowser fDialog = new System.Windows.Forms.Design.FolderNameEditor.FolderBrowser();
public FolderDialog()
{
}
public DialogResult DisplayDialog()
{
return DisplayDialog("请选择一个文件夹");
}
public DialogResult DisplayDialog(string description)
{
fDialog.Description = description;
return fDialog.ShowDialog();
}
public string Path
{
get
{
return fDialog.DirectoryPath;
}
}
~FolderDialog()
{
fDialog.Dispose();
}
}
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.LinkLabel linkLabel2;
private System.Windows.Forms.TextBox path1;
private System.Windows.Forms.TextBox path2;
private System.Windows.Forms.TextBox width;
private System.Windows.Forms.TextBox height;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.LinkLabel linkLabel3;
private System.Windows.Forms.LinkLabel linkLabel4;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
private ArrayList threads = new ArrayList();
private ArrayList images = new ArrayList();
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.linkLabel2 = new System.Windows.Forms.LinkLabel();
this.path1 = new System.Windows.Forms.TextBox();
this.path2 = new System.Windows.Forms.TextBox();
this.width = new System.Windows.Forms.TextBox();
this.height = new System.Windows.Forms.TextBox();
this.listView1 = new System.Windows.Forms.ListView();
this.linkLabel3 = new System.Windows.Forms.LinkLabel();
this.linkLabel4 = new System.Windows.Forms.LinkLabel();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// linkLabel1
//
this.linkLabel1.Location = new System.Drawing.Point(456, 16);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(32, 16);
this.linkLabel1.TabIndex = 0;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "浏览";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// linkLabel2
//
this.linkLabel2.Location = new System.Drawing.Point(456, 48);
this.linkLabel2.Name = "linkLabel2";
this.linkLabel2.Size = new System.Drawing.Size(32, 16);
this.linkLabel2.TabIndex = 1;
this.linkLabel2.TabStop = true;
this.linkLabel2.Text = "浏览";
this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
//
// path1
//
this.path1.Location = new System.Drawing.Point(16, 16);
this.path1.Name = "path1";
this.path1.Size = new System.Drawing.Size(432, 21);
this.p