- ·上一篇内容:使用c#生成随机数总结
- ·下一篇内容:pictureBox1的Image属性获得图片路径的三种方法
使用C#批量生成缩略图的工具源代码
/// <summary>
/// 应用程序的主入口点.
/// </summary> [STAThread] static void Main( )
{
Application.Run( new Form1( ) );
}
private void linkLabel1_LinkClicked( object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
{
FolderDialog dlg = new FolderDialog( );
if( dlg.DisplayDialog( )==DialogResult.OK )
path1.Text = dlg.Path;
}
private void linkLabel2_LinkClicked( object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
{
FolderDialog dlg = new FolderDialog( );
if( dlg.DisplayDialog( )==DialogResult.OK )
path2.Text = dlg.Path;
}
private void linkLabel3_LinkClicked( object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
{
string[] img = Directory.GetFiles( path1.Text, "*.jpg" );
listView1.Items.Add( new ListViewItem( new
string[]
{
path1.Text, path2.Text, width.Text, height.Text, img.Length.ToString( ), "0"
}
) );
}
private void linkLabel4_LinkClicked( object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e )
{
foreach( ListViewItem item in listView1.Items )
{
Thread t = new Thread( new ThreadStart( Process ) );
t.Start( );
threads.Add( t );
}
}
private void Process( )
{
int index = threads.IndexOf( Thread.CurrentThread );
ListViewItem item = listView1.Items[index];
string path1 = item.SubItems[0].Text;
string path2 = item.SubItems[1].Text;
int width =
int.Parse( item.SubItems[2].Text );
int height =
int.Parse( item.SubItems[3].Text );
int i = 0;
foreach( string file1 in Directory.GetFiles( path1, "*.jpg" ) )
{
i ;
string file2 = path2 @"" Path.GetFileName( file1 );
ImageConvert.ShowThumbnail( file1,file2, height, width );
lock( listView1 )
{
listView1.Items[index].SubItems[5].Text = i.ToString( );
}
}
}
}
}
原文地址:http://lanustudio.bokee.com/viewdiary.25518139.html
本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!
微信搜索“优雅的代码”关注本站的公众号,或直接使用微信扫描下面二维码关注本站公众号,以获取最新内容。
个人成长离不开各位的关注,你的关注就是我继续前行的动力。