├── Nd.test ├── obj │ └── Debug │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ │ ├── Nd.test.exe │ │ ├── Nd.test.pdb │ │ ├── DesignTimeResolveAssemblyReferences.cache │ │ ├── Nd.test.csprojResolveAssemblyReference.cache │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ └── Nd.test.csproj.FileListAbsolute.txt ├── bin │ └── Debug │ │ ├── Nd.test.exe │ │ ├── Nd.test.pdb │ │ ├── Nd.test.vshost.exe │ │ ├── Nd.test.exe.config │ │ ├── Nd.test.vshost.exe.config │ │ └── Nd.test.vshost.exe.manifest ├── App.config ├── Properties │ └── AssemblyInfo.cs ├── Nd.test.csproj └── Program.cs ├── Nd.CompressImg ├── bin │ └── Debug │ │ ├── HandDataLog │ │ └── 2015-5 │ │ │ ├── 11.txt │ │ │ └── 13.txt │ │ ├── Nd.CompressImg.exe │ │ ├── Nd.CompressImg.pdb │ │ ├── Nd.CompressImg.vshost.exe │ │ ├── Nd.CompressImg.exe.config │ │ ├── Nd.CompressImg.vshost.exe.config │ │ ├── Nd.CompressImg.application │ │ ├── Nd.CompressImg.vshost.application │ │ ├── Nd.CompressImg.exe.manifest │ │ └── Nd.CompressImg.vshost.exe.manifest ├── obj │ └── Debug │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ │ ├── Nd.CompressImg.exe │ │ ├── Nd.CompressImg.pdb │ │ ├── Nd.CompressImg.Form1.resources │ │ ├── DesignTimeResolveAssemblyReferences.cache │ │ ├── Nd.CompressImg.Properties.Resources.resources │ │ ├── Nd.CompressImg.csproj.GenerateResource.Cache │ │ ├── TempPE │ │ └── Properties.Resources.Designer.cs.dll │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ ├── Nd.CompressImg.csprojResolveAssemblyReference.cache │ │ ├── Nd.CompressImg.csproj.FileListAbsolute.txt │ │ ├── Nd.CompressImg.application │ │ └── Nd.CompressImg.exe.manifest ├── Nd.CompressImg_TemporaryKey.pfx ├── App.config ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Nd.CompressImg.csproj.user ├── Program.cs ├── untility │ └── MyCompare.cs ├── model │ └── EventMessage.cs ├── logcontext │ └── LogContext.cs ├── extention │ └── MyListExtension.cs ├── Controller │ ├── HandleForImgController2.cs │ └── HandleForImgController.cs ├── Form1.resx ├── Nd.CompressImg.csproj ├── handler │ └── HandlerForImg.cs ├── Form1.cs └── Form1.Designer.cs ├── image └── project.png ├── Nd.CompressImg.v12.suo ├── README.md └── Nd.CompressImg.sln /Nd.test/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Nd.test/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Nd.test/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/HandDataLog/2015-5/11.txt: -------------------------------------------------------------------------------- 1 | 96 2 | 96 3 | 96 4 | 96 5 | 96 6 | -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /image/project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/image/project.png -------------------------------------------------------------------------------- /Nd.CompressImg.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg.v12.suo -------------------------------------------------------------------------------- /Nd.test/bin/Debug/Nd.test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/bin/Debug/Nd.test.exe -------------------------------------------------------------------------------- /Nd.test/bin/Debug/Nd.test.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/bin/Debug/Nd.test.pdb -------------------------------------------------------------------------------- /Nd.test/obj/Debug/Nd.test.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/obj/Debug/Nd.test.exe -------------------------------------------------------------------------------- /Nd.test/obj/Debug/Nd.test.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/obj/Debug/Nd.test.pdb -------------------------------------------------------------------------------- /Nd.test/bin/Debug/Nd.test.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/bin/Debug/Nd.test.vshost.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nd.CompressImg 2 | 多线程批量压缩图片工具 3 | ![image](https://github.com/taomylife521/Nd.CompressImg/blob/master/image/project.png) 4 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/bin/Debug/Nd.CompressImg.exe -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/bin/Debug/Nd.CompressImg.pdb -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/Nd.CompressImg.exe -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/Nd.CompressImg.pdb -------------------------------------------------------------------------------- /Nd.CompressImg/Nd.CompressImg_TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/Nd.CompressImg_TemporaryKey.pfx -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/bin/Debug/Nd.CompressImg.vshost.exe -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.Form1.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/Nd.CompressImg.Form1.resources -------------------------------------------------------------------------------- /Nd.test/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /Nd.test/obj/Debug/Nd.test.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/obj/Debug/Nd.test.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Nd.test/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.test/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/Nd.CompressImg.Properties.Resources.resources -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.csproj.GenerateResource.Cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/Nd.CompressImg.csproj.GenerateResource.Cache -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taomylife521/Nd.CompressImg/HEAD/Nd.CompressImg/obj/Debug/Nd.CompressImg.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Nd.test/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Nd.CompressImg/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Nd.test/bin/Debug/Nd.test.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Nd.test/bin/Debug/Nd.test.vshost.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.vshost.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Nd.CompressImg/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Nd.test/obj/Debug/Nd.test.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\test Project\Nd.CompressImg\Nd.test\bin\Debug\Nd.test.exe.config 2 | D:\test Project\Nd.CompressImg\Nd.test\bin\Debug\Nd.test.exe 3 | D:\test Project\Nd.CompressImg\Nd.test\bin\Debug\Nd.test.pdb 4 | D:\test Project\Nd.CompressImg\Nd.test\obj\Debug\Nd.test.exe 5 | D:\test Project\Nd.CompressImg\Nd.test\obj\Debug\Nd.test.pdb 6 | D:\test Project\Nd.CompressImg\Nd.test\obj\Debug\Nd.test.csprojResolveAssemblyReference.cache 7 | -------------------------------------------------------------------------------- /Nd.CompressImg/Nd.CompressImg.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | zh-CN 11 | false 12 | 13 | -------------------------------------------------------------------------------- /Nd.test/bin/Debug/Nd.test.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Nd.CompressImg/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace Nd.CompressImg 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Nd.CompressImg/untility/MyCompare.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Nd.CompressImg.untility 10 | { 11 | public class MyCompare: IComparer 12 | { 13 | 14 | 15 | 16 | public int Compare(DirectoryInfo x, DirectoryInfo y) 17 | { 18 | int xi = int.Parse(x.Name); 19 | int yi = int.Parse(y.Name); 20 | return xi == yi ? 0 : (xi > yi ? 1 : -1); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Nd.CompressImg/model/EventMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Nd.CompressImg.model 8 | { 9 | public class EventMessage:EventArgs 10 | { 11 | public string msg { get; set; } 12 | 13 | 14 | } 15 | 16 | public class DealResult 17 | { 18 | //public string taskId { get; set; } 19 | 20 | public int sucessCount { get; set; } 21 | 22 | public int failCount { get; set; } 23 | 24 | public double totalTime { get; set; } 25 | 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Nd.CompressImg/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.34014 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Nd.CompressImg.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Nd.test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Nd.test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Nd.test")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("fc87dd15-b616-42bc-835b-6888de795996")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Nd.CompressImg/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("Nd.CompressImg")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Nd.CompressImg")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f971c06f-9fcd-424c-bd77-f92ffd9e6f70")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\test Project\Nd.CompressImg\Nd.CompressImg\bin\Debug\Nd.CompressImg.exe.config 2 | D:\test Project\Nd.CompressImg\Nd.CompressImg\bin\Debug\Nd.CompressImg.exe 3 | D:\test Project\Nd.CompressImg\Nd.CompressImg\bin\Debug\Nd.CompressImg.pdb 4 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.Form1.resources 5 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.Properties.Resources.resources 6 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.csproj.GenerateResource.Cache 7 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.exe 8 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.pdb 9 | D:\test Project\Nd.CompressImg\Nd.CompressImg\bin\Debug\Nd.CompressImg.exe.manifest 10 | D:\test Project\Nd.CompressImg\Nd.CompressImg\bin\Debug\Nd.CompressImg.application 11 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.exe.manifest 12 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.application 13 | D:\test Project\Nd.CompressImg\Nd.CompressImg\obj\Debug\Nd.CompressImg.csprojResolveAssemblyReference.cache 14 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/HandDataLog/2015-5/13.txt: -------------------------------------------------------------------------------- 1 | 压缩不成功,路径名:E:\上传图片\引导页压缩后\1.png错误信息:GDI+ 中发生一般性错误。,堆栈: 在 System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) 2 | 在 Nd.CompressImg.handler.HandlerForImg.GetPicThumbnail(String sFile, String dFile, String& errMsg, Int32 dHeight, Int32 dWidth, Int32 flag) 位置 d:\test Project\Nd.CompressImg\Nd.CompressImg\handler\HandlerForImg.cs:行号 221InnerException: 3 | 压缩不成功,路径名:E:\上传图片\引导页压缩后\2.png错误信息:GDI+ 中发生一般性错误。,堆栈: 在 System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) 4 | 在 Nd.CompressImg.handler.HandlerForImg.GetPicThumbnail(String sFile, String dFile, String& errMsg, Int32 dHeight, Int32 dWidth, Int32 flag) 位置 d:\test Project\Nd.CompressImg\Nd.CompressImg\handler\HandlerForImg.cs:行号 221InnerException: 5 | 压缩不成功,路径名:E:\上传图片\引导页压缩后\3.png错误信息:GDI+ 中发生一般性错误。,堆栈: 在 System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) 6 | 在 Nd.CompressImg.handler.HandlerForImg.GetPicThumbnail(String sFile, String dFile, String& errMsg, Int32 dHeight, Int32 dWidth, Int32 flag) 位置 d:\test Project\Nd.CompressImg\Nd.CompressImg\handler\HandlerForImg.cs:行号 221InnerException: 7 | -------------------------------------------------------------------------------- /Nd.CompressImg/logcontext/LogContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Nd.CompressImg.logcontext 9 | { 10 | public class LogContext 11 | { 12 | public void AddLogInfo(string strPath, string txt, bool isAppend) 13 | { 14 | string strDirecory = strPath.Substring(0, strPath.LastIndexOf('\\')); 15 | if (!Directory.Exists(strDirecory)) 16 | { 17 | Directory.CreateDirectory(strDirecory); 18 | } 19 | if (!File.Exists(strPath)) 20 | { 21 | File.Create(strPath).Dispose(); 22 | } 23 | 24 | StreamWriter fs; 25 | if (isAppend) fs = File.AppendText(strPath); 26 | else fs = File.CreateText(strPath); 27 | 28 | fs.WriteLine(txt); 29 | fs.Flush(); 30 | fs.Close(); 31 | fs.Dispose(); 32 | } 33 | 34 | 35 | public string ReadDataLog(string strPath) 36 | { 37 | if (!File.Exists(strPath)) 38 | { 39 | File.Create(strPath).Dispose(); 40 | } 41 | 42 | string txt = File.ReadAllText(strPath, Encoding.UTF8); 43 | 44 | return txt; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Nd.CompressImg.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nd.CompressImg", "Nd.CompressImg\Nd.CompressImg.csproj", "{7656D952-328B-450C-9292-7F8E6D5A0AF6}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nd.test", "Nd.test\Nd.test.csproj", "{1C94FA9A-2094-424A-AFBE-524D65FA809A}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7656D952-328B-450C-9292-7F8E6D5A0AF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {7656D952-328B-450C-9292-7F8E6D5A0AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {7656D952-328B-450C-9292-7F8E6D5A0AF6}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {7656D952-328B-450C-9292-7F8E6D5A0AF6}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {1C94FA9A-2094-424A-AFBE-524D65FA809A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {1C94FA9A-2094-424A-AFBE-524D65FA809A}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {1C94FA9A-2094-424A-AFBE-524D65FA809A}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {1C94FA9A-2094-424A-AFBE-524D65FA809A}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.application: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Lev4PcnyR73N1js+CNvAshTHZrY= 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.application: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Lev4PcnyR73N1js+CNvAshTHZrY= 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.vshost.application: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Lev4PcnyR73N1js+CNvAshTHZrY= 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Nd.CompressImg/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.34014 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Nd.CompressImg.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Nd.CompressImg.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Nd.CompressImg/extention/MyListExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Nd.CompressImg.extention 8 | { 9 | public static class MyListExtension 10 | { 11 | public static void TryAddImgFile(this List lst, string filePath) 12 | { 13 | string extension = Path.GetExtension(filePath).ToLower(); 14 | if (extension == ".jpg" || extension == ".jpeg" || extension == ".gif" || extension == ".bmp" || extension == ".png") 15 | { 16 | lst.Add(filePath); 17 | } 18 | 19 | 20 | } 21 | 22 | } 23 | 24 | 25 | public static class MyDictionaryExtension 26 | { 27 | public static void AddFile(this Dictionary> dic, string filePath) 28 | { 29 | string extension = Path.GetExtension(filePath).ToLower(); 30 | if (extension == ".jpg" || extension == ".jpeg" || extension == ".gif" || extension == ".bmp" || extension == ".png") 31 | { 32 | 33 | dic.TryAdd(".img",filePath); 34 | } 35 | else 36 | { 37 | dic.TryAdd(extension, filePath); 38 | } 39 | 40 | } 41 | 42 | public static void TryAdd(this Dictionary> dic, string key,object filePath) 43 | { 44 | 45 | if(dic.ContainsKey(key)) 46 | { 47 | string str = filePath as string; 48 | if (str != null) 49 | { 50 | dic[key].Add(str); 51 | } 52 | List lstStr = filePath as List; 53 | if(lstStr != null && lstStr.Count > 0) 54 | { 55 | dic[key].AddRange(lstStr); 56 | } 57 | 58 | } 59 | else 60 | { 61 | 62 | List lst = new List(); 63 | string str = filePath as string; 64 | if (str != null) 65 | { 66 | lst.Add(str); 67 | } 68 | List lstStr = filePath as List; 69 | if (lstStr != null && lstStr.Count > 0) 70 | { 71 | lst.AddRange(lstStr); 72 | } 73 | dic.Add(key, lst); 74 | 75 | } 76 | 77 | 78 | 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Nd.test/Nd.test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1C94FA9A-2094-424A-AFBE-524D65FA809A} 8 | Exe 9 | Properties 10 | Nd.test 11 | Nd.test 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Designer 51 | 52 | 53 | 54 | 61 | -------------------------------------------------------------------------------- /Nd.CompressImg/Controller/HandleForImgController2.cs: -------------------------------------------------------------------------------- 1 | using Nd.CompressImg.handler; 2 | using Nd.CompressImg.model; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace Nd.CompressImg.publisher 11 | { 12 | 13 | public class HandleForImgController2 14 | { 15 | 16 | 17 | //private HandlerForImg handler = null; 18 | private CancellationTokenSource importCts =new CancellationTokenSource(); 19 | private Task[] tasks = null; 20 | public event EventHandler onProcessCompleteHandler; 21 | 22 | // public event EventHandler onWorklingMsg; 23 | 24 | 25 | public HandleForImgController2(int taskCount) 26 | { 27 | // handler = _handler; 28 | tasks = new Task[taskCount]; 29 | 30 | 31 | } 32 | 33 | 34 | /// 35 | /// 开启线程 36 | /// 37 | /// 线程休息时间 38 | /// 文件夹路径 39 | /// 要处理最小的文件夹名称 40 | /// 要处理最大的文件夹名称 41 | public void StartWork(int _timeSpan,int minIndex,int maxIndex,string[] fileName,string outPutPath,int taskIndex) 42 | { 43 | //tasks[taskIndex] = Task.Factory.StartNew((x) => 44 | //{ 45 | // EventMessage eventmsg = null; 46 | // HandlerForImg handler = new HandlerForImg(); 47 | // if (!importCts.IsCancellationRequested) 48 | // { 49 | // eventmsg= handler.DoWork(this, minIndex, maxIndex, fileName,outPutPath, this.tasks[taskIndex].Id.ToString()); 50 | // //handler.onWorklingMsg += (obj, arg) => 51 | // //{ 52 | // // onWorklingMsg(this, arg); 53 | // //}; 54 | // onProcessCompleteHandler(this, eventmsg); 55 | // Thread.Sleep(_timeSpan); 56 | // } 57 | // else 58 | // { 59 | // eventmsg = new EventMessage { taskId = this.tasks[taskIndex].Id.ToString(), msg = "线程被终止", failCount = eventmsg == null ? "0" : eventmsg.failCount, sucessCount = eventmsg.sucessCount == null ? "0" : eventmsg.sucessCount, totalTime = eventmsg.totalTime == null ? "0" : eventmsg.totalTime }; 60 | // onProcessCompleteHandler(this, eventmsg); 61 | // } 62 | //}, importCts.Token);//,importCts 63 | 64 | 65 | } 66 | 67 | public void StopWork() 68 | { 69 | importCts.Cancel(); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ENFWRcYaaGt8qVIHbVjVwBRzRKo= 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 06MAsbgFUGlKhu1U3KJ4fh8CRLU= 63 | 64 | 65 | -------------------------------------------------------------------------------- /Nd.CompressImg/obj/Debug/Nd.CompressImg.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ENFWRcYaaGt8qVIHbVjVwBRzRKo= 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 06MAsbgFUGlKhu1U3KJ4fh8CRLU= 63 | 64 | 65 | -------------------------------------------------------------------------------- /Nd.CompressImg/bin/Debug/Nd.CompressImg.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | ENFWRcYaaGt8qVIHbVjVwBRzRKo= 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 06MAsbgFUGlKhu1U3KJ4fh8CRLU= 63 | 64 | 65 | -------------------------------------------------------------------------------- /Nd.CompressImg/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Nd.CompressImg/Form1.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /Nd.CompressImg/Nd.CompressImg.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7656D952-328B-450C-9292-7F8E6D5A0AF6} 8 | WinExe 9 | Properties 10 | Nd.CompressImg 11 | Nd.CompressImg 12 | v4.0 13 | 512 14 | false 15 | E:\bb\ 16 | true 17 | Disk 18 | false 19 | Foreground 20 | 7 21 | Days 22 | false 23 | false 24 | true 25 | true 26 | 1 27 | 1.0.0.%2a 28 | false 29 | true 30 | true 31 | 32 | 33 | 34 | AnyCPU 35 | true 36 | full 37 | false 38 | bin\Debug\ 39 | DEBUG;TRACE 40 | prompt 41 | 4 42 | 43 | 44 | AnyCPU 45 | pdbonly 46 | true 47 | bin\Release\ 48 | TRACE 49 | prompt 50 | 4 51 | 52 | 53 | 9C4358DF8A1CD81CC90B520B0DAEF904A99B6FA4 54 | 55 | 56 | Nd.CompressImg_TemporaryKey.pfx 57 | 58 | 59 | true 60 | 61 | 62 | true 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | Form 82 | 83 | 84 | Form1.cs 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | Form1.cs 95 | 96 | 97 | ResXFileCodeGenerator 98 | Resources.Designer.cs 99 | Designer 100 | 101 | 102 | True 103 | Resources.resx 104 | True 105 | 106 | 107 | 108 | SettingsSingleFileGenerator 109 | Settings.Designer.cs 110 | 111 | 112 | True 113 | Settings.settings 114 | True 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | False 123 | Microsoft .NET Framework 4.5 %28x86 和 x64%29 124 | true 125 | 126 | 127 | False 128 | .NET Framework 3.5 SP1 Client Profile 129 | false 130 | 131 | 132 | False 133 | .NET Framework 3.5 SP1 134 | false 135 | 136 | 137 | 138 | 145 | -------------------------------------------------------------------------------- /Nd.test/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Drawing.Imaging; 7 | using System.Drawing; 8 | using System.Drawing.Drawing2D; 9 | using System.IO; 10 | using System.Threading; 11 | using System.Collections.Concurrent; 12 | 13 | namespace Nd.test 14 | { 15 | class Program 16 | { 17 | static void Main(string[] args) 18 | { 19 | #region 多线程 20 | //List demoData = new List(); 21 | //Parallel.For(0, 96, num => 22 | //{ 23 | // demoData.Add(num.ToString()); 24 | //}); 25 | //// 以上是生成一个测试用的数组,我就不考虑线程安全的问题了 26 | //var tasks = new ConcurrentBag(); 27 | //ConcurrentBag sum = new ConcurrentBag(); 28 | //sum.Add(0); 29 | //CancellationTokenSource importCts = new CancellationTokenSource(); 30 | 31 | //Task.Factory.StartNew(() => 32 | //{ 33 | // while (true) 34 | // { 35 | // Console.WriteLine("输入e或者q可以取消任务。"); 36 | // string input = (Console.ReadLine() ?? "").ToLower(); 37 | // if (input == "e" || input == "q") 38 | // { 39 | // importCts.Cancel(); 40 | // Console.WriteLine("已发出取消请求。"); 41 | // break; 42 | // } 43 | // } 44 | //}); 45 | 46 | //// 开启管理Task 47 | //Task t = Task.Factory.StartNew(() => 48 | //{ 49 | // int maxCount = 10, currentCount = 0; 50 | // int tempCount = 0; 51 | // while (demoData.Count > 0 && !importCts.Token.IsCancellationRequested) 52 | // { 53 | // Console.WriteLine("当前共{0}个子任务。", currentCount); 54 | // while (currentCount >= maxCount) 55 | // { 56 | // int index = Task.WaitAny(tasks.ToArray()); 57 | // Console.WriteLine("子任务ID={0}已完成。", tasks.ToArray()[index].Id); 58 | // currentCount--; 59 | // } 60 | // Thread.Sleep(1000); 61 | // // 10可以做成可配置的值 62 | // List childData = demoData.Take(50).ToList(); 63 | // tempCount += childData.Count; 64 | // if (childData.Count > 0) 65 | // { 66 | // demoData.RemoveRange(0, childData.Count); 67 | // Console.WriteLine("分配50个到子任务……"); 68 | // Task subTask = Task.Factory.StartNew(() => 69 | // { 70 | // DoSomeWork(childData, importCts.Token); 71 | // }, importCts.Token); 72 | // // Thread.Sleep(3000); 73 | // currentCount++; 74 | // tasks.Add(subTask); 75 | // } 76 | // else if (tempCount == 96) 77 | // { 78 | // if (currentCount < maxCount) 79 | // { 80 | // maxCount = currentCount; 81 | // } 82 | // Console.WriteLine("全部分配完毕。"); 83 | // } 84 | // else 85 | // { 86 | // Console.WriteLine("全部分配完毕。"); 87 | // } 88 | // } 89 | //}, importCts.Token).ContinueWith(task => 90 | //{ 91 | // Console.WriteLine("管理Task已退出。"); 92 | //}); 93 | #endregion 94 | 95 | GetPicThumbnail("c:\\1.jpg", "C:\\2.jpg", 200, 100, 60); 96 | Console.WriteLine("压缩成功"); 97 | Console.ReadKey(); 98 | //Test(); 99 | } 100 | 101 | private static void DoSomeWork(List data, CancellationToken token) 102 | { 103 | foreach (string d in data) 104 | { 105 | if (token.IsCancellationRequested) 106 | { 107 | Console.WriteLine("任务已被取消。"); 108 | break; 109 | } 110 | 111 | Console.WriteLine(d); 112 | Thread.Sleep(200); 113 | } 114 | } 115 | 116 | private static void Test() 117 | { 118 | bool flag = GetPicThumbnail("D:\\1.jpg", "D:\\2.jpg", 746 / 2, 1366 / 2, 70); 119 | if (flag) 120 | { 121 | Console.WriteLine("压缩成功"); 122 | } 123 | Console.ReadKey(); 124 | } 125 | 126 | #region GetPicThumbnail 127 | /// 128 | /// 无损压缩图片 129 | /// 130 | /// 原图片 131 | /// 压缩后保存位置 132 | /// 高度 133 | /// 134 | /// 压缩质量 1-100 135 | /// 136 | 137 | public static bool GetPicThumbnail(string sFile, string dFile, int dHeight, int dWidth, int flag) 138 | { 139 | System.Drawing.Image iSource = System.Drawing.Image.FromFile(sFile); 140 | 141 | ImageFormat tFormat = iSource.RawFormat; 142 | 143 | int sW = 0, sH = 0; 144 | 145 | //按比例缩放 146 | 147 | Size tem_size = new Size(iSource.Width, iSource.Height); 148 | if (tem_size.Width > dHeight || tem_size.Width > dWidth) //将**改成c#中的或者操作符号 149 | { 150 | 151 | if ((tem_size.Width * dHeight) > (tem_size.Height * dWidth)) 152 | { 153 | sW = dWidth; 154 | sH = (dWidth * tem_size.Height) / tem_size.Width; 155 | } 156 | 157 | else 158 | { 159 | sH = dHeight; 160 | sW = (tem_size.Width * dHeight) / tem_size.Height; 161 | } 162 | 163 | } 164 | 165 | else 166 | { 167 | sW = tem_size.Width; 168 | sH = tem_size.Height; 169 | 170 | } 171 | 172 | Bitmap ob = new Bitmap(dWidth, dHeight); 173 | Graphics g = Graphics.FromImage(ob); 174 | g.Clear(Color.WhiteSmoke); 175 | g.CompositingQuality = CompositingQuality.HighQuality; 176 | g.SmoothingMode = SmoothingMode.HighQuality; 177 | g.InterpolationMode = InterpolationMode.HighQualityBicubic; 178 | g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel); 179 | g.Dispose(); 180 | //以下代码为保存图片时,设置压缩质量 181 | EncoderParameters ep = new EncoderParameters(); 182 | long[] qy = new long[1]; 183 | qy[0] = flag;//设置压缩的比例1-100 184 | EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy); 185 | ep.Param[0] = eParam; 186 | try 187 | { 188 | ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); 189 | ImageCodecInfo jpegICIinfo = null; 190 | for (int x = 0; x < arrayICI.Length; x++) 191 | { 192 | if (arrayICI[x].FormatDescription.Equals("JPEG")) 193 | { 194 | jpegICIinfo = arrayICI[x]; 195 | break; 196 | } 197 | } 198 | if (jpegICIinfo != null) 199 | { 200 | ob.Save(dFile, jpegICIinfo, ep);//dFile是压缩后的新路径 201 | } 202 | else 203 | { 204 | ob.Save(dFile, tFormat); 205 | } 206 | return true; 207 | } 208 | catch 209 | { 210 | return false; 211 | } 212 | finally 213 | { 214 | iSource.Dispose(); 215 | ob.Dispose(); 216 | } 217 | 218 | 219 | 220 | } 221 | #endregion 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /Nd.CompressImg/handler/HandlerForImg.cs: -------------------------------------------------------------------------------- 1 | using Nd.CompressImg.logcontext; 2 | using Nd.CompressImg.model; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.Drawing; 7 | using System.Drawing.Drawing2D; 8 | using System.Drawing.Imaging; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | 14 | namespace Nd.CompressImg.handler 15 | { 16 | public class HandlerForImg 17 | { 18 | // public event EventHandler onWorklingMsg; 19 | 20 | //// public event EventHandler onProgressChange; 21 | 22 | // /// 23 | // /// 发送消息 24 | // /// 25 | // /// 消息内容 26 | // private void ShowMsgToForm(EventMessage eventMsg) 27 | // { 28 | // onWorklingMsg(this, eventMsg); 29 | // } 30 | 31 | ///// 32 | ///// 处理文件夹下的图片 33 | ///// 34 | ///// 35 | ///// 36 | ///// 37 | ///// 38 | // public EventMessage DoWork(object sender, int minIndex, int maxIndex, string[] fileName, string outPutPath, string taskId) 39 | //{ 40 | 41 | // string siPath = "";//要处理的源文件夹路径 42 | // string siFile = "";//要处理的源文件 43 | // string diPath = "";//要放置的目录 44 | // string diFile = "";//要放置的目的文件 45 | // string errMsg = "";//记录压缩错误信息 46 | // int sucessCount = 0;//成功数量 47 | // int failCount = 0;//失败数量 48 | // Stopwatch st = new Stopwatch(); 49 | // LogContext log = new LogContext(); 50 | // string path = System.IO.Directory.GetCurrentDirectory(); 51 | 52 | // DateTime CurrTime = DateTime.Now; 53 | // string strPath = path + "\\HandDataLog\\" + CurrTime.Year + "-" + CurrTime.Month + "\\" + CurrTime.Day + ".txt"; 54 | // st.Start(); 55 | // for (int i = minIndex; i < maxIndex; i++) 56 | // { 57 | // siPath = fileName[i];//要处理的最小文件夹路径 58 | // DirectoryInfo si = new DirectoryInfo(siPath); 59 | // if (Directory.Exists(siPath))//判断原路径是否存在,如果存在则处理 60 | // { 61 | // diPath = TryCreateOutPutPath(Path.Combine(outPutPath, si.Name)); 62 | // DirectoryInfo di = new DirectoryInfo(siPath);//获取原路径下的所有文件 63 | // FileInfo[] fiArr = di.GetFiles(); 64 | // #region 循环遍历进行处理 65 | // for (int j = 0; j < fiArr.Length; j++) 66 | // { 67 | // siFile = fiArr[j].FullName; //Path.Combine(siPath, fiArr[j].ToString()); 68 | // diFile = Path.Combine(diPath, fiArr[j].Name); 69 | // if (diFile != "") 70 | // { 71 | // bool r = GetPicThumbnail(siFile, diFile, ref errMsg);//压缩 72 | // if (!r) 73 | // { 74 | // failCount++; 75 | // //压缩不成功,要进行记录日志,并输出控制台 76 | // ShowMsgToForm( 77 | // new EventMessage 78 | // { 79 | // msg = "压缩不成功,路径名:" + siFile + "线程id:" + taskId + "错误信息:" + errMsg, 80 | // taskId = taskId, 81 | // failCount = failCount.ToString(), 82 | // sucessCount = sucessCount.ToString(), 83 | // totalTime = st.ElapsedMilliseconds.ToString() 84 | // } 85 | // ); 86 | 87 | // log.AddLogInfo(strPath, "压缩不成功,路径名:" + siFile + "线程id:" + taskId + "错误信息:" + errMsg, true); 88 | // } 89 | // sucessCount++; 90 | // ShowMsgToForm(new EventMessage 91 | // { 92 | // msg = "压缩成功,输出路径:" + diFile, 93 | // taskId = taskId, 94 | // failCount = failCount.ToString(), 95 | // sucessCount = sucessCount.ToString(), 96 | // totalTime = st.ElapsedMilliseconds.ToString() 97 | // }); 98 | 99 | // } 100 | // } 101 | // #endregion 102 | // } 103 | // } 104 | // st.Stop(); 105 | // EventMessage eventMsg = new EventMessage 106 | // { 107 | // msg = "压缩完毕", 108 | // taskId = taskId, 109 | // failCount = failCount.ToString(), 110 | // sucessCount = sucessCount.ToString(), 111 | // totalTime = st.ElapsedMilliseconds.ToString() 112 | // }; 113 | // ShowMsgToForm(eventMsg); 114 | // return eventMsg; 115 | 116 | 117 | //} 118 | 119 | #region 尝试创建输出路径 120 | /// 121 | /// 尝试创建输出路径 122 | /// 123 | /// 124 | /// 125 | public string TryCreateOutPutPath(string outPutPath) 126 | { 127 | try 128 | { 129 | if (!Directory.Exists(outPutPath)) 130 | { 131 | outPutPath = Directory.CreateDirectory(outPutPath).FullName; 132 | } 133 | 134 | return outPutPath; 135 | } 136 | catch (Exception ex) 137 | { 138 | return ""; 139 | } 140 | } 141 | #endregion 142 | 143 | #region GetPicThumbnail 144 | /// 145 | /// 无损压缩图片 146 | /// 147 | /// 原图片 148 | /// 压缩后保存位置 149 | /// 高度 150 | /// 151 | /// 压缩质量 1-100 152 | /// 153 | 154 | public static bool GetPicThumbnail(string sFile, string dFile, ref string errMsg,int dHeight=0, int dWidth=0, int flag=60) 155 | { 156 | System.Drawing.Image iSource = System.Drawing.Image.FromFile(sFile); 157 | 158 | ImageFormat tFormat = iSource.RawFormat; 159 | 160 | int sW = 0, sH = 0; 161 | 162 | //按比例缩放 163 | 164 | Size tem_size = new Size(iSource.Width, iSource.Height); 165 | dHeight = dHeight == 0 ? tem_size.Height : dHeight; 166 | dWidth = dWidth == 0 ? tem_size.Width : dWidth; 167 | if (tem_size.Width > dHeight || tem_size.Width > dWidth) //将**改成c#中的或者操作符号 168 | { 169 | 170 | if ((tem_size.Width * dHeight) > (tem_size.Height * dWidth)) 171 | { 172 | sW = dWidth; 173 | sH = (dWidth * tem_size.Height) / tem_size.Width; 174 | } 175 | 176 | else 177 | { 178 | sH = dHeight; 179 | sW = (tem_size.Width * dHeight) / tem_size.Height; 180 | } 181 | 182 | } 183 | 184 | else 185 | { 186 | sW = tem_size.Width; 187 | sH = tem_size.Height; 188 | 189 | } 190 | 191 | Bitmap ob = new Bitmap(dWidth, dHeight); 192 | Graphics g = Graphics.FromImage(ob); 193 | g.Clear(Color.WhiteSmoke); 194 | g.CompositingQuality = CompositingQuality.HighQuality; 195 | g.SmoothingMode = SmoothingMode.HighQuality; 196 | g.InterpolationMode = InterpolationMode.HighQualityBicubic; 197 | g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel); 198 | g.Dispose(); 199 | //以下代码为保存图片时,设置压缩质量 200 | EncoderParameters ep = new EncoderParameters(); 201 | long[] qy = new long[1]; 202 | qy[0] = flag;//设置压缩的比例1-100 203 | EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy); 204 | ep.Param[0] = eParam; 205 | try 206 | { 207 | ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); 208 | ImageCodecInfo jpegICIinfo = null; 209 | for (int x = 0; x < arrayICI.Length; x++) 210 | { 211 | if (arrayICI[x].FormatDescription.Equals("JPEG")) 212 | { 213 | jpegICIinfo = arrayICI[x]; 214 | break; 215 | } 216 | } 217 | 218 | 219 | if (jpegICIinfo != null) 220 | { 221 | ob.Save(dFile, jpegICIinfo, ep);//dFile是压缩后的新路径 222 | } 223 | else 224 | { 225 | ob.Save(dFile, tFormat); 226 | } 227 | return true; 228 | } 229 | catch(Exception ex) 230 | { 231 | errMsg = ex.Message+",堆栈:"+ex.StackTrace+"InnerException:"+ex.InnerException; 232 | return false; 233 | } 234 | finally 235 | { 236 | iSource.Dispose(); 237 | ob.Dispose(); 238 | } 239 | 240 | 241 | 242 | } 243 | #endregion 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /Nd.CompressImg/Controller/HandleForImgController.cs: -------------------------------------------------------------------------------- 1 | using Nd.CompressImg.handler; 2 | using Nd.CompressImg.logcontext; 3 | using Nd.CompressImg.model; 4 | using System; 5 | using System.Collections.Concurrent; 6 | using System.Collections.Generic; 7 | using System.Diagnostics; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Text; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | 14 | namespace Nd.CompressImg.Controller 15 | { 16 | public class HandleForImgController 17 | { 18 | ConcurrentBag> tasks = new ConcurrentBag>(); 19 | CancellationTokenSource importCts = new CancellationTokenSource();//是否取消 20 | public static event EventHandler onProcessingHandler;//处理中的事件 21 | public static event EventHandler onProcessCompleteHandler;//处理完成后的事件 22 | 23 | public static event EventHandler onAllTaskCompleteHandler;//处理所有任务完成后的事件 24 | /// 25 | /// 开启多线程 26 | /// 27 | /// 要处理的数据集合 28 | /// 单次处理数据量 29 | /// 最大开启的线程数 30 | public void StartWork(List dealDataCollection,Dictionary> dicAllFile,string InPuth,string outPutPath,int singleDealCount,int dHeight=0,int dWidth = 0,int quality=60,int maxTaskCount = 10,bool isCopyOtherFile=true) 31 | { 32 | try 33 | { 34 | Stopwatch st = new Stopwatch(); 35 | st.Start(); 36 | DealResult dResult = new DealResult(); 37 | if (isCopyOtherFile) 38 | { 39 | onProcessCompleteHandler(this, new EventMessage { msg = "开始复制其它文件..." }); 40 | //专门复制其他文件的线程 41 | Task.Factory.StartNew(() => 42 | { 43 | string tempPath = ""; 44 | string tempDic = ""; 45 | int sumCount = 0; 46 | Stopwatch st2 = new Stopwatch(); 47 | DealResult dResult2 = new DealResult(); 48 | st.Start(); 49 | foreach (KeyValuePair> item in dicAllFile) 50 | { 51 | if (item.Key != ".img") 52 | { 53 | item.Value.ForEach(x => 54 | { 55 | tempPath = x; 56 | tempDic = Path.GetDirectoryName(x.Replace(InPuth, outPutPath)); 57 | if (!Directory.Exists(tempDic)) 58 | { 59 | Directory.CreateDirectory(tempDic); 60 | } 61 | File.Copy(tempPath, x.Replace(InPuth, outPutPath)); 62 | sumCount++; 63 | }); 64 | } 65 | } 66 | st2.Stop(); 67 | dResult2.sucessCount = sumCount; 68 | dResult2.failCount = 0; 69 | dResult2.totalTime = st2.ElapsedMilliseconds / 1000; 70 | return dResult2; 71 | 72 | }, importCts.Token).ContinueWith(task => 73 | { 74 | onProcessCompleteHandler(this, new EventMessage { msg = "其它文件全部复制完毕!" }); 75 | }, importCts.Token); 76 | } 77 | 78 | 79 | //开启管理Task 80 | Task.Factory.StartNew(() => 81 | { 82 | int currentTaskCount = 0; 83 | DealResult dresult = new DealResult(); 84 | while (dealDataCollection.Count > 0 && !importCts.Token.IsCancellationRequested) 85 | { 86 | 87 | while (currentTaskCount >= maxTaskCount) 88 | { 89 | 90 | int index= Task.WaitAny(tasks.ToArray());//等待任何一个task完成 91 | // Task task = tasks[index] as Task; 92 | onProcessCompleteHandler(this, new EventMessage { msg = "线程" + tasks.ToArray()[index].Id.ToString() + "处理完成,成功数量:" + tasks.ToArray()[index].Result.sucessCount.ToString() + ",失败数量:" + tasks.ToArray()[index].Result.failCount.ToString() + ",耗时:" + tasks.ToArray()[index].Result.totalTime.ToString() + "" }); 93 | currentTaskCount--; 94 | 95 | } 96 | // Thread.Sleep(50); 97 | 98 | List childData = dealDataCollection.Take(singleDealCount).ToList(); 99 | 100 | if (childData.Count > 0) 101 | { 102 | dealDataCollection.RemoveRange(0, childData.Count); 103 | Task subTask = Task.Factory.StartNew(() => 104 | { 105 | 106 | return DoSomeWork(childData, importCts.Token, outPutPath, InPuth,dHeight,dWidth,quality); 107 | }, importCts.Token); 108 | //dResult.failCount += subTask.Result.failCount; 109 | //dResult.sucessCount += subTask.Result.sucessCount; 110 | //dResult.totalTime += subTask.Result.totalTime; 111 | // onProcessCompleteHandler(this, new EventMessage { msg = "线程" + subTask.Id.ToString() + "处理完成,成功数量:" + subTask.Result.sucessCount.ToString() + ",失败数量:" + subTask.Result.failCount.ToString() + ",耗时:" + subTask.Result.totalTime.ToString() + "" }); 112 | 113 | currentTaskCount++; 114 | tasks.Add(subTask); 115 | } 116 | else //如果分配完毕currentTaskCount 128 | { 129 | 130 | //showMsg(this, new EventMessage { msg = "" }); 131 | Task.WaitAll(tasks.ToArray());//防止管理线程分配完毕,子线程还没有处理完毕 132 | st.Stop(); 133 | tasks.ToList().ForEach(x => 134 | { 135 | 136 | dResult.failCount += x.Result.failCount; 137 | dResult.sucessCount += x.Result.sucessCount; 138 | }); 139 | if(!importCts.Token.IsCancellationRequested) 140 | { 141 | onAllTaskCompleteHandler(this, new EventMessage { msg = "全部处理完毕" }); 142 | } 143 | 144 | onProcessCompleteHandler(this, new EventMessage { msg = "成功数量:" + dResult.sucessCount.ToString() + ",失败数量:" + dResult.failCount.ToString() + ",耗时:" + (st.ElapsedMilliseconds/1000).ToString() + "" }); 145 | }); 146 | } 147 | catch(Exception ex) 148 | { 149 | 150 | } 151 | } 152 | 153 | public void StopWork() 154 | { 155 | importCts.Cancel(); 156 | } 157 | private DealResult DoSomeWork(List srcColletion, CancellationToken token, string outPutPath,string InPath,int dHeight,int dWidth,int flag) 158 | { 159 | string errMsg = ""; 160 | LogContext log = new LogContext(); 161 | string path = System.IO.Directory.GetCurrentDirectory(); 162 | DateTime CurrTime = DateTime.Now; 163 | DealResult res = new DealResult(); 164 | string strPath = path + "\\HandDataLog\\" + CurrTime.Year + "-" + CurrTime.Month + "\\" + CurrTime.Day + ".txt"; 165 | Stopwatch st = new Stopwatch(); 166 | st.Start(); 167 | string diFile = ""; 168 | foreach (string siFile in srcColletion) 169 | { 170 | // FileInfo fi = new FileInfo(siFile); 171 | diFile= siFile.Replace(InPath, outPutPath); 172 | if(!Directory.Exists(Path.GetDirectoryName(diFile))) 173 | { 174 | Directory.CreateDirectory(Path.GetDirectoryName(diFile)); 175 | } 176 | 177 | if (token.IsCancellationRequested) 178 | { 179 | showMsg(this, new EventMessage { msg = "线程"+Task.CurrentId+"任务已经取消!" });//"线程"+id.ToString()+ 180 | onAllTaskCompleteHandler(this, new EventMessage { msg = "线程" + Thread.CurrentThread.ManagedThreadId + "任务被终止!" });//"线程"+id.ToString()+ 181 | break; 182 | } 183 | bool r = HandlerForImg.GetPicThumbnail(siFile, diFile, ref errMsg,dHeight,dWidth,flag); 184 | if(!r) 185 | { 186 | res.failCount += 1; 187 | showMsg(this, new EventMessage { msg = "压缩不成功,路径名:" + siFile + "错误信息:" + errMsg }); 188 | log.AddLogInfo(strPath, "压缩不成功,路径名:" + siFile + "错误信息:" + errMsg, true); 189 | } 190 | showMsg(this, new EventMessage { msg = "压缩成功,输出路径:" + diFile }); 191 | //log.AddLogInfo(strPath, "压缩成功,输出路径:" + diFile, true); 192 | res.sucessCount += 1; 193 | } 194 | st.Stop(); 195 | res.totalTime += st.ElapsedMilliseconds / 1000; 196 | //Thread.Sleep(1000); 197 | return res; 198 | } 199 | 200 | private void showMsg(object sender,EventMessage eventMsg) 201 | { 202 | onProcessingHandler(sender, eventMsg); 203 | } 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /Nd.CompressImg/Form1.cs: -------------------------------------------------------------------------------- 1 | using Nd.CompressImg.Controller; 2 | using Nd.CompressImg.handler; 3 | using Nd.CompressImg.logcontext; 4 | using Nd.CompressImg.model; 5 | using Nd.CompressImg.publisher; 6 | using Nd.CompressImg.untility; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.ComponentModel; 10 | using System.Data; 11 | using System.Diagnostics; 12 | using System.Drawing; 13 | using System.IO; 14 | using System.Linq; 15 | using System.Text; 16 | using System.Threading.Tasks; 17 | using System.Windows.Forms; 18 | using Nd.CompressImg.extention; 19 | 20 | namespace Nd.CompressImg 21 | { 22 | 23 | public partial class Form1 : Form 24 | { 25 | HandleForImgController handlerController = null;//线程控制类 26 | HandlerForImg _handler = null;//真正用于处理的类 27 | 28 | Action showMsg = null; //封装一个用于向LISTBOX控件显示信息的方法 29 | 30 | Action showResult = null; //封装一个用于显示最终结果的方法 31 | Action showTime = null; 32 | Stopwatch st = new Stopwatch(); 33 | private List directoryList =null; 34 | private int allFolderCount = 0; 35 | private static Dictionary> allFileList = null; 36 | 37 | //event EventHandler onListBoxItemAdded; 38 | 39 | 40 | public Form1() 41 | { 42 | InitializeComponent(); 43 | _handler = new HandlerForImg(); 44 | // handlerController = new HandleForImgController(_handler, 1); 45 | handlerController = new HandleForImgController(); 46 | for(int i = 1;i<101;i++) 47 | { 48 | cmbQuality.Items.Add(i.ToString()); 49 | 50 | } 51 | cmbQuality.SelectedIndex = 59; 52 | } 53 | 54 | 55 | #region 打开处理路径 56 | 57 | private void btnPath_Click(object sender, EventArgs e) 58 | { 59 | try 60 | { 61 | 62 | FolderBrowserDialog openFolder = new FolderBrowserDialog(); 63 | if (openFolder.ShowDialog() == DialogResult.OK) 64 | { 65 | txtPath.Text = openFolder.SelectedPath.ToString(); 66 | 67 | allFileList = Task>>.Factory.StartNew(() => 68 | { return GetAllDirectory(txtPath.Text, this.ChbIsSubFolder.Checked); }).Result; 69 | directoryList = allFileList.ContainsKey(".img")==true?allFileList[".img"]:null;//GetDirectory(txtPath.Text, this.ChbIsSubFolder.Checked); 70 | int sumFile = 0; 71 | this.lstDetail.Items.Clear(); 72 | string fileExtention = ""; 73 | foreach (KeyValuePair> item in allFileList) 74 | { 75 | fileExtention = item.Key == "" ? "未知类型" : item.Key; 76 | lstDetail.Items.Add("文件类型:" + fileExtention + ",数量:" + item.Value.Count); 77 | sumFile += item.Value.Count; 78 | } 79 | lstDetail.Items.Add("文件总数量:" + sumFile.ToString()); 80 | } 81 | InitData(); 82 | } 83 | catch(Exception ex) 84 | { 85 | MessageBox.Show("异常消息:" + ex.Message + "\r\n堆栈跟踪:" + ex.StackTrace); 86 | } 87 | } 88 | #endregion 89 | 90 | #region 初始化数据 91 | public void InitData() 92 | { 93 | DisEnabledTask(); 94 | string dealPath = this.txtPath.Text; 95 | if (dealPath != "") 96 | { 97 | int folderCount = Directory.GetDirectories(dealPath).Length; 98 | int fileCount = Directory.GetFiles(dealPath).Length; 99 | if (directoryList != null) 100 | { 101 | this.lbFileCount.Text = "图片数量:" + directoryList.Count.ToString(); 102 | } 103 | else 104 | { 105 | this.lbFileCount.Text = "图片数量:0"; 106 | } 107 | this.lbFolderCount.Text = "文件夹数量:" + allFolderCount.ToString(); 108 | 109 | } 110 | this.lbDealPath.Text ="处理路径:"+ this.txtPath.Text; 111 | this.lbOutPath.Text ="输出路径:"+ this.txtOutPath.Text; 112 | } 113 | #endregion 114 | 115 | #region 开启线程 116 | /// 117 | /// 开启 118 | /// 119 | /// 120 | /// 121 | private void btnStart_Click(object sender, EventArgs e) 122 | { 123 | #region 旧代码 124 | // EnabledTask(); 125 | // string path = txtPath.Text; 126 | // string outPutPath = txtOutPath.Text; 127 | // if (path.Length <= 0) 128 | // { 129 | // MessageBox.Show("处理路径不能为空"); 130 | // DisEnabledTask(); 131 | // return; 132 | // } 133 | // else if (!Directory.Exists(path)) 134 | // { 135 | // MessageBox.Show("处理路径不存在"); 136 | // DisEnabledTask(); 137 | // return; 138 | // } 139 | // outPutPath = outPutPath.Length <= 0 ? @"c:\pic" : outPutPath;//设置默认输出路径 140 | // path = path.Length <= 0 ? @"E:\上传图片\pic" : path;//设置默认处理路径 141 | // int leastCount = txtLeastCount.Text.Length <= 0 ? 2 : Convert.ToInt32(txtLeastCount.Text);//每个线程至少处理数量 142 | // int taskCount =txtTaskCount.Text.Length <= 0 ? 2:Convert.ToInt32(txtTaskCount.Text);//默认开始线程数量 143 | 144 | // int timespan = System.Configuration.ConfigurationManager.AppSettings["timespan"] == null ? 1 : int.Parse(System.Configuration.ConfigurationManager.AppSettings["timespan"]); 145 | // string[] diArr = Directory.GetDirectories(path);//获取一共要处理的文件夹 146 | 147 | // #region 自动优化处理数量和开启线程数量 148 | // int dealCount = 0; 149 | // int extraCount = 0; 150 | // if (diArr.Length <= leastCount)//小于等于每个线程要至少处理的数量 151 | // { 152 | // taskCount = 1; 153 | // leastCount = diArr.Length; 154 | // //重置自定义的选择线程数量 155 | // } 156 | // else 157 | // { 158 | // dealCount = diArr.Length / taskCount;//每个线程需要处理的数量 159 | // extraCount = diArr.Length % taskCount;//给每个线程分配完后剩余的数量 160 | // if (dealCount < leastCount)//控制每个线程至少处理leastCount个以上的文件夹,如果小于leastCount则重新计算要开启的线程数量 161 | // { 162 | // taskCount = diArr.Length / leastCount + diArr.Length % leastCount == 0 ? 0 : diArr.Length % leastCount; 163 | // } 164 | // else//如果处理的数量超过至少要处理的数量 165 | // { 166 | // leastCount = dealCount; 167 | // } 168 | // } 169 | // #endregion 170 | 171 | //// handlerController = new HandleForImgController(_handler, taskCount); 172 | // handlerController = new HandleForImgController(taskCount); 173 | 174 | // int minIndex = 0; 175 | // int maxIndex = 0; 176 | // for (int i = 0; i < taskCount; i++)//开启多线程,为每个线程分配处理数量 177 | // { 178 | // minIndex = i==0 ? 0:i*leastCount; 179 | // maxIndex =i == taskCount - 1 ? (i + 1) * leastCount-1 +extraCount : ((i + 1) * leastCount) - 1;// 180 | // //0 n-1 181 | // // n 2n-1 182 | // //2n 3n-1 183 | // handlerController.StartWork(timespan, minIndex, maxIndex, diArr, outPutPath,i); 184 | // } 185 | 186 | // this.txtLeastCount.Text = leastCount.ToString(); 187 | // this.txtTaskCount.Text = taskCount.ToString(); 188 | // lbForTaskCount.Text ="开启线程数量:"+ taskCount.ToString(); 189 | // lbForSleepTime.Text = "线程处理频率:" + this.cmbSleepTime.SelectedItem.ToString(); 190 | #endregion 191 | 192 | try 193 | { 194 | string inPath = txtPath.Text.ToString(); 195 | if (inPath == "" || !Directory.Exists(inPath)) 196 | { 197 | MessageBox.Show("处理路径不能为空或不存在"); 198 | return; 199 | } 200 | 201 | string outPath = txtOutPath.Text.ToString(); 202 | if (outPath == "" || !Directory.Exists(outPath)) 203 | { 204 | MessageBox.Show("输出路径不能为空或不存在"); 205 | return; 206 | } 207 | int r; 208 | bool r2 = int.TryParse(this.txtLeastCount.Text, out r); 209 | if (!r2) 210 | { 211 | MessageBox.Show("线程至少处理数量格式不对"); 212 | return; 213 | } 214 | if (lbFileCount.Text == "图片数量:0") 215 | { 216 | MessageBox.Show("当前处理路径下无任何图片"); 217 | return; 218 | } 219 | if (txtCompressHeight.Text == "") 220 | { 221 | MessageBox.Show("当前处理路径下无任何图片"); 222 | return; 223 | } 224 | int dHeight = Convert.ToInt32(txtCompressHeight.Text); 225 | int dWidth = Convert.ToInt32(txtCompressWidth.Text); 226 | 227 | if (dHeight > 0) 228 | { 229 | if (dWidth <= 0) 230 | { 231 | MessageBox.Show("压缩宽高指定错误!"); 232 | return; 233 | } 234 | } 235 | if (dWidth > 0) 236 | { 237 | if (dHeight <= 0) 238 | { 239 | MessageBox.Show("压缩宽高指定错误!"); 240 | return; 241 | } 242 | } 243 | allFileList = Task>>.Factory.StartNew(() => 244 | { return GetAllDirectory(txtPath.Text, this.ChbIsSubFolder.Checked); }).Result; 245 | int quality = Convert.ToInt32(this.cmbQuality.SelectedItem); 246 | int dealCount = Convert.ToInt32(r) <= 0 ? 50 : Convert.ToInt32(r); 247 | int maxTaskCount = Convert.ToInt32(this.txtMaxTask.Text) <= 0 ? 10 : Convert.ToInt32(this.txtMaxTask.Text); 248 | EnabledTask(); 249 | 250 | Reset(); 251 | this.timer1.Start();//开启计时器 252 | 253 | handlerController.StartWork(allFileList[".img"], allFileList, txtPath.Text.ToString(), txtOutPath.Text, dealCount,dHeight,dWidth,quality, maxTaskCount, this.chbCopyOtherFile.Checked);//开启多线程 254 | } 255 | catch(Exception ex) 256 | { 257 | MessageBox.Show("错误消息:" + ex.Message + "\r\n" + "堆栈:" + ex.StackTrace); 258 | } 259 | 260 | } 261 | #endregion 262 | 263 | 264 | #region 重置 265 | public void Reset() 266 | { 267 | this.lbTime.Text = "0"; 268 | this.lsbResult.Items.Clear(); 269 | this.lstLog.Items.Clear(); 270 | this.lbDealing.Text = ""; 271 | } 272 | #endregion 273 | public void theout(object source,System.Timers.ElapsedEventArgs e) 274 | { 275 | this.lbTime.Text = "已用时:" + e.SignalTime; 276 | } 277 | 278 | #region 开始 279 | public void EnabledTask() 280 | { 281 | this.btnStart.Enabled = false; 282 | this.btnStop.Enabled = true; 283 | } 284 | 285 | 286 | public void DisEnabledTask() 287 | { 288 | this.btnStart.Enabled = true; 289 | this.btnStop.Enabled = false; 290 | } 291 | #endregion 292 | 293 | #region 窗体载入 294 | private void Form1_Load(object sender, EventArgs e) 295 | { 296 | 297 | showMsg = new Action((txt) => 298 | { 299 | if (this.lstLog.Items.Count >= 34) this.lstLog.Items.Remove(this.lstLog.Items[0]); 300 | this.lstLog.Items.Add( txt.msg); 301 | lbDealing.Text = txt.msg; 302 | }); 303 | showResult = new Action((txt) => 304 | { 305 | if (this.lsbResult.Items.Count >= 300) this.lsbResult.Items.Remove(this.lsbResult.Items[0]); 306 | lsbResult.Items.Add(DateTime.Now.ToString() +":"+ txt.msg); 307 | }); 308 | 309 | showTime = new Action((txt) => 310 | { 311 | this.timer1.Stop(); 312 | this.btnStart.Enabled = true; 313 | this.btnStop.Enabled = true; 314 | lsbResult.Items.Add(DateTime.Now.ToString() +":"+ txt.msg); 315 | }); 316 | 317 | HandleForImgController.onProcessingHandler += (obj, arg) => 318 | { 319 | this.Invoke(showMsg, arg); 320 | }; 321 | HandleForImgController.onProcessCompleteHandler += (obj, arg) => 322 | { 323 | this.Invoke(showResult, arg); 324 | }; 325 | 326 | HandleForImgController.onAllTaskCompleteHandler += (obj, arg) => 327 | { 328 | this.Invoke(showTime, arg); 329 | }; 330 | //LogContext log = new LogContext(); 331 | //this.onListBoxItemAdded += (obj, arg) => 332 | //{ 333 | // try 334 | // { 335 | // string path = System.IO.Directory.GetCurrentDirectory(); 336 | // DateTime CurrTime = DateTime.Now; 337 | // string strPath = path + "\\HandDataLog\\" + CurrTime.Year + "-" + CurrTime.Month + "\\" + CurrTime.Day + ".txt"; 338 | // //log.AddLogInfo(strPath,arg.taskId+arg.msg, true); 339 | // } 340 | // catch { } 341 | //}; 342 | } 343 | #endregion 344 | 345 | #region 停止工作 346 | private void btnStop_Click(object sender, EventArgs e) 347 | { 348 | handlerController.StopWork(); 349 | DisEnabledTask(); 350 | } 351 | #endregion 352 | 353 | #region 打开输出路径 354 | private void btnOutPath_Click(object sender, EventArgs e) 355 | { 356 | FolderBrowserDialog openFolder = new FolderBrowserDialog(); 357 | if (openFolder.ShowDialog() == DialogResult.OK) 358 | { 359 | txtOutPath.Text=openFolder.SelectedPath.ToString(); 360 | } 361 | InitData(); 362 | } 363 | #endregion 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | /// 372 | /// 获取或设置控件的值,根据控件的Id与字典的key匹配值 373 | /// 374 | /// 控件集合 375 | /// 字典集合 376 | private static List GetDirectory(string directoryPath,bool isGetSubFolder =true) 377 | { 378 | 379 | List directoryList = new List(); 380 | 381 | Directory.GetFiles(directoryPath).ToList().ForEach(x =>//先添加当前目录下的所有文件 382 | { 383 | 384 | directoryList.TryAddImgFile(x); 385 | 386 | 387 | }); 388 | if(!isGetSubFolder) 389 | { 390 | return directoryList; 391 | } 392 | var directsName = Directory.GetDirectories(directoryPath); 393 | foreach (string directName in directsName) 394 | { 395 | if(File.Exists(directName)) 396 | { 397 | directoryList.TryAddImgFile(directName); 398 | } 399 | else if (Directory.Exists(directName)) 400 | { 401 | string[] filesNameChilds = Directory.GetDirectories(directName); 402 | if (filesNameChilds != null && filesNameChilds.Count() > 0) 403 | { 404 | filesNameChilds.ToList().ForEach(x => GetDirectory(x)); 405 | //GetDirectory(directName); 406 | } 407 | else 408 | { 409 | Directory.GetFiles(directName).ToList().ForEach(x=>{ 410 | 411 | directoryList.TryAddImgFile(x); 412 | 413 | }); 414 | } 415 | } 416 | 417 | 418 | } 419 | return directoryList; 420 | } 421 | 422 | 423 | /// 424 | /// 获取或设置控件的值,根据控件的Id与字典的key匹配值 425 | /// 426 | /// 控件集合 427 | /// 字典集合 428 | private Dictionary> GetAllDirectory(string directoryPath, bool isGetSubFolder = true) 429 | { 430 | 431 | Dictionary> directoryList = new Dictionary>(); 432 | Directory.GetFiles(directoryPath).ToList().ForEach(x =>//先添加当前目录下的所有文件 433 | { 434 | directoryList.AddFile(x); 435 | }); 436 | if (!isGetSubFolder) 437 | { 438 | return directoryList; 439 | } 440 | var directsName = Directory.GetDirectories(directoryPath); 441 | allFolderCount += directsName.Length; 442 | foreach (string item in directsName) 443 | { 444 | Dictionary> dic = GetAllDirectory(item, isGetSubFolder); 445 | 446 | dic.ToList().ForEach(x => 447 | { 448 | directoryList.TryAdd(x.Key, x.Value); 449 | }); 450 | 451 | 452 | } 453 | return directoryList; 454 | 455 | 456 | 457 | 458 | } 459 | 460 | 461 | 462 | private void timer1_Tick(object sender, EventArgs e) 463 | { 464 | int r =Convert.ToInt32(this.lbTime.Text.ToString()); 465 | this.lbTime.Text = (++r).ToString(); 466 | } 467 | 468 | private void ChbIsSubFolder_CheckedChanged(object sender, EventArgs e) 469 | { 470 | directoryList = GetDirectory(txtPath.Text, this.ChbIsSubFolder.Checked); 471 | InitData(); 472 | } 473 | 474 | 475 | } 476 | 477 | 478 | } 479 | -------------------------------------------------------------------------------- /Nd.CompressImg/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Nd.CompressImg 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.btnStart = new System.Windows.Forms.Button(); 33 | this.lstLog = new System.Windows.Forms.ListBox(); 34 | this.btnStop = new System.Windows.Forms.Button(); 35 | this.txtPath = new System.Windows.Forms.TextBox(); 36 | this.btnPath = new System.Windows.Forms.Button(); 37 | this.label1 = new System.Windows.Forms.Label(); 38 | this.label2 = new System.Windows.Forms.Label(); 39 | this.txtOutPath = new System.Windows.Forms.TextBox(); 40 | this.btnOutPath = new System.Windows.Forms.Button(); 41 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 42 | this.lstDetail = new System.Windows.Forms.ListBox(); 43 | this.lbFileCount = new System.Windows.Forms.Label(); 44 | this.lbFolderCount = new System.Windows.Forms.Label(); 45 | this.lbOutPath = new System.Windows.Forms.Label(); 46 | this.lbDealPath = new System.Windows.Forms.Label(); 47 | this.txtLeastCount = new System.Windows.Forms.TextBox(); 48 | this.label7 = new System.Windows.Forms.Label(); 49 | this.groupBox2 = new System.Windows.Forms.GroupBox(); 50 | this.lsbResult = new System.Windows.Forms.ListBox(); 51 | this.lbDealing = new System.Windows.Forms.Label(); 52 | this.lbTime = new System.Windows.Forms.Label(); 53 | this.timer1 = new System.Windows.Forms.Timer(this.components); 54 | this.label8 = new System.Windows.Forms.Label(); 55 | this.ChbIsSubFolder = new System.Windows.Forms.CheckBox(); 56 | this.label3 = new System.Windows.Forms.Label(); 57 | this.txtMaxTask = new System.Windows.Forms.TextBox(); 58 | this.chbCopyOtherFile = new System.Windows.Forms.CheckBox(); 59 | this.cmbQuality = new System.Windows.Forms.ComboBox(); 60 | this.label4 = new System.Windows.Forms.Label(); 61 | this.label6 = new System.Windows.Forms.Label(); 62 | this.label9 = new System.Windows.Forms.Label(); 63 | this.txtCompressHeight = new System.Windows.Forms.TextBox(); 64 | this.txtCompressWidth = new System.Windows.Forms.TextBox(); 65 | this.label5 = new System.Windows.Forms.Label(); 66 | this.label10 = new System.Windows.Forms.Label(); 67 | this.groupBox1.SuspendLayout(); 68 | this.groupBox2.SuspendLayout(); 69 | this.SuspendLayout(); 70 | // 71 | // btnStart 72 | // 73 | this.btnStart.Location = new System.Drawing.Point(383, 166); 74 | this.btnStart.Name = "btnStart"; 75 | this.btnStart.Size = new System.Drawing.Size(75, 23); 76 | this.btnStart.TabIndex = 0; 77 | this.btnStart.Text = "开启"; 78 | this.btnStart.UseVisualStyleBackColor = true; 79 | this.btnStart.Click += new System.EventHandler(this.btnStart_Click); 80 | // 81 | // lstLog 82 | // 83 | this.lstLog.BackColor = System.Drawing.Color.Black; 84 | this.lstLog.ForeColor = System.Drawing.Color.White; 85 | this.lstLog.FormattingEnabled = true; 86 | this.lstLog.ItemHeight = 12; 87 | this.lstLog.Location = new System.Drawing.Point(-2, 207); 88 | this.lstLog.Name = "lstLog"; 89 | this.lstLog.Size = new System.Drawing.Size(561, 220); 90 | this.lstLog.TabIndex = 1; 91 | // 92 | // btnStop 93 | // 94 | this.btnStop.Location = new System.Drawing.Point(484, 166); 95 | this.btnStop.Name = "btnStop"; 96 | this.btnStop.Size = new System.Drawing.Size(75, 23); 97 | this.btnStop.TabIndex = 2; 98 | this.btnStop.Text = "停止"; 99 | this.btnStop.UseVisualStyleBackColor = true; 100 | this.btnStop.Click += new System.EventHandler(this.btnStop_Click); 101 | // 102 | // txtPath 103 | // 104 | this.txtPath.Location = new System.Drawing.Point(70, 13); 105 | this.txtPath.Name = "txtPath"; 106 | this.txtPath.Size = new System.Drawing.Size(408, 21); 107 | this.txtPath.TabIndex = 3; 108 | // 109 | // btnPath 110 | // 111 | this.btnPath.Location = new System.Drawing.Point(484, 13); 112 | this.btnPath.Name = "btnPath"; 113 | this.btnPath.Size = new System.Drawing.Size(75, 23); 114 | this.btnPath.TabIndex = 4; 115 | this.btnPath.Text = "处理路径"; 116 | this.btnPath.UseVisualStyleBackColor = true; 117 | this.btnPath.Click += new System.EventHandler(this.btnPath_Click); 118 | // 119 | // label1 120 | // 121 | this.label1.AutoSize = true; 122 | this.label1.Location = new System.Drawing.Point(11, 18); 123 | this.label1.Name = "label1"; 124 | this.label1.Size = new System.Drawing.Size(53, 12); 125 | this.label1.TabIndex = 5; 126 | this.label1.Text = "处理路径"; 127 | // 128 | // label2 129 | // 130 | this.label2.AutoSize = true; 131 | this.label2.Location = new System.Drawing.Point(11, 43); 132 | this.label2.Name = "label2"; 133 | this.label2.Size = new System.Drawing.Size(53, 12); 134 | this.label2.TabIndex = 5; 135 | this.label2.Text = "输出路径"; 136 | // 137 | // txtOutPath 138 | // 139 | this.txtOutPath.Location = new System.Drawing.Point(71, 43); 140 | this.txtOutPath.Name = "txtOutPath"; 141 | this.txtOutPath.Size = new System.Drawing.Size(407, 21); 142 | this.txtOutPath.TabIndex = 6; 143 | // 144 | // btnOutPath 145 | // 146 | this.btnOutPath.Location = new System.Drawing.Point(484, 46); 147 | this.btnOutPath.Name = "btnOutPath"; 148 | this.btnOutPath.Size = new System.Drawing.Size(75, 23); 149 | this.btnOutPath.TabIndex = 7; 150 | this.btnOutPath.Text = "输出路径"; 151 | this.btnOutPath.UseVisualStyleBackColor = true; 152 | this.btnOutPath.Click += new System.EventHandler(this.btnOutPath_Click); 153 | // 154 | // groupBox1 155 | // 156 | this.groupBox1.Controls.Add(this.label5); 157 | this.groupBox1.Controls.Add(this.lstDetail); 158 | this.groupBox1.Controls.Add(this.lbFileCount); 159 | this.groupBox1.Controls.Add(this.lbFolderCount); 160 | this.groupBox1.Controls.Add(this.lbOutPath); 161 | this.groupBox1.Controls.Add(this.lbDealPath); 162 | this.groupBox1.Location = new System.Drawing.Point(585, 5); 163 | this.groupBox1.Name = "groupBox1"; 164 | this.groupBox1.Size = new System.Drawing.Size(422, 166); 165 | this.groupBox1.TabIndex = 14; 166 | this.groupBox1.TabStop = false; 167 | this.groupBox1.Text = "处理明细"; 168 | // 169 | // lstDetail 170 | // 171 | this.lstDetail.FormattingEnabled = true; 172 | this.lstDetail.ItemHeight = 12; 173 | this.lstDetail.Location = new System.Drawing.Point(8, 102); 174 | this.lstDetail.Name = "lstDetail"; 175 | this.lstDetail.Size = new System.Drawing.Size(379, 64); 176 | this.lstDetail.TabIndex = 11; 177 | // 178 | // lbFileCount 179 | // 180 | this.lbFileCount.AutoSize = true; 181 | this.lbFileCount.Location = new System.Drawing.Point(148, 17); 182 | this.lbFileCount.Name = "lbFileCount"; 183 | this.lbFileCount.Size = new System.Drawing.Size(65, 12); 184 | this.lbFileCount.TabIndex = 10; 185 | this.lbFileCount.Text = "图片数量:"; 186 | // 187 | // lbFolderCount 188 | // 189 | this.lbFolderCount.AutoSize = true; 190 | this.lbFolderCount.Location = new System.Drawing.Point(6, 18); 191 | this.lbFolderCount.Name = "lbFolderCount"; 192 | this.lbFolderCount.Size = new System.Drawing.Size(77, 12); 193 | this.lbFolderCount.TabIndex = 9; 194 | this.lbFolderCount.Text = "文件夹数量:"; 195 | // 196 | // lbOutPath 197 | // 198 | this.lbOutPath.AutoSize = true; 199 | this.lbOutPath.Location = new System.Drawing.Point(6, 66); 200 | this.lbOutPath.Name = "lbOutPath"; 201 | this.lbOutPath.Size = new System.Drawing.Size(65, 12); 202 | this.lbOutPath.TabIndex = 6; 203 | this.lbOutPath.Text = "输出路径:"; 204 | // 205 | // lbDealPath 206 | // 207 | this.lbDealPath.AutoSize = true; 208 | this.lbDealPath.Location = new System.Drawing.Point(6, 41); 209 | this.lbDealPath.Name = "lbDealPath"; 210 | this.lbDealPath.Size = new System.Drawing.Size(65, 12); 211 | this.lbDealPath.TabIndex = 6; 212 | this.lbDealPath.Text = "处理路径:"; 213 | // 214 | // txtLeastCount 215 | // 216 | this.txtLeastCount.Location = new System.Drawing.Point(129, 70); 217 | this.txtLeastCount.Name = "txtLeastCount"; 218 | this.txtLeastCount.Size = new System.Drawing.Size(46, 21); 219 | this.txtLeastCount.TabIndex = 16; 220 | this.txtLeastCount.Text = "50"; 221 | // 222 | // label7 223 | // 224 | this.label7.AutoSize = true; 225 | this.label7.Location = new System.Drawing.Point(11, 73); 226 | this.label7.Name = "label7"; 227 | this.label7.Size = new System.Drawing.Size(101, 12); 228 | this.label7.TabIndex = 17; 229 | this.label7.Text = "线程至少处理数量"; 230 | // 231 | // groupBox2 232 | // 233 | this.groupBox2.Controls.Add(this.lsbResult); 234 | this.groupBox2.Location = new System.Drawing.Point(579, 177); 235 | this.groupBox2.Name = "groupBox2"; 236 | this.groupBox2.Size = new System.Drawing.Size(428, 250); 237 | this.groupBox2.TabIndex = 19; 238 | this.groupBox2.TabStop = false; 239 | this.groupBox2.Text = "处理结果"; 240 | // 241 | // lsbResult 242 | // 243 | this.lsbResult.BackColor = System.Drawing.Color.Black; 244 | this.lsbResult.ForeColor = System.Drawing.Color.Green; 245 | this.lsbResult.FormattingEnabled = true; 246 | this.lsbResult.ItemHeight = 12; 247 | this.lsbResult.Location = new System.Drawing.Point(0, 14); 248 | this.lsbResult.Name = "lsbResult"; 249 | this.lsbResult.Size = new System.Drawing.Size(422, 232); 250 | this.lsbResult.TabIndex = 15; 251 | // 252 | // lbDealing 253 | // 254 | this.lbDealing.AutoSize = true; 255 | this.lbDealing.Location = new System.Drawing.Point(5, 191); 256 | this.lbDealing.Name = "lbDealing"; 257 | this.lbDealing.Size = new System.Drawing.Size(59, 12); 258 | this.lbDealing.TabIndex = 20; 259 | this.lbDealing.Text = "正在处理:"; 260 | // 261 | // lbTime 262 | // 263 | this.lbTime.AutoSize = true; 264 | this.lbTime.Location = new System.Drawing.Point(75, 177); 265 | this.lbTime.Name = "lbTime"; 266 | this.lbTime.Size = new System.Drawing.Size(11, 12); 267 | this.lbTime.TabIndex = 21; 268 | this.lbTime.Text = "0"; 269 | // 270 | // timer1 271 | // 272 | this.timer1.Interval = 1000; 273 | this.timer1.Tick += new System.EventHandler(this.timer1_Tick); 274 | // 275 | // label8 276 | // 277 | this.label8.AutoSize = true; 278 | this.label8.Location = new System.Drawing.Point(4, 177); 279 | this.label8.Name = "label8"; 280 | this.label8.Size = new System.Drawing.Size(65, 12); 281 | this.label8.TabIndex = 22; 282 | this.label8.Text = "已用时(s):"; 283 | // 284 | // ChbIsSubFolder 285 | // 286 | this.ChbIsSubFolder.AutoSize = true; 287 | this.ChbIsSubFolder.Checked = true; 288 | this.ChbIsSubFolder.CheckState = System.Windows.Forms.CheckState.Checked; 289 | this.ChbIsSubFolder.Location = new System.Drawing.Point(199, 72); 290 | this.ChbIsSubFolder.Name = "ChbIsSubFolder"; 291 | this.ChbIsSubFolder.Size = new System.Drawing.Size(120, 16); 292 | this.ChbIsSubFolder.TabIndex = 23; 293 | this.ChbIsSubFolder.Text = "是否处理子文件夹"; 294 | this.ChbIsSubFolder.UseVisualStyleBackColor = true; 295 | this.ChbIsSubFolder.CheckedChanged += new System.EventHandler(this.ChbIsSubFolder_CheckedChanged); 296 | // 297 | // label3 298 | // 299 | this.label3.AutoSize = true; 300 | this.label3.Location = new System.Drawing.Point(12, 101); 301 | this.label3.Name = "label3"; 302 | this.label3.Size = new System.Drawing.Size(77, 12); 303 | this.label3.TabIndex = 25; 304 | this.label3.Text = "最大线程数量"; 305 | // 306 | // txtMaxTask 307 | // 308 | this.txtMaxTask.Location = new System.Drawing.Point(130, 98); 309 | this.txtMaxTask.Name = "txtMaxTask"; 310 | this.txtMaxTask.Size = new System.Drawing.Size(46, 21); 311 | this.txtMaxTask.TabIndex = 24; 312 | this.txtMaxTask.Text = "50"; 313 | // 314 | // chbCopyOtherFile 315 | // 316 | this.chbCopyOtherFile.AutoSize = true; 317 | this.chbCopyOtherFile.Checked = true; 318 | this.chbCopyOtherFile.CheckState = System.Windows.Forms.CheckState.Checked; 319 | this.chbCopyOtherFile.Location = new System.Drawing.Point(199, 97); 320 | this.chbCopyOtherFile.Name = "chbCopyOtherFile"; 321 | this.chbCopyOtherFile.Size = new System.Drawing.Size(228, 16); 322 | this.chbCopyOtherFile.TabIndex = 26; 323 | this.chbCopyOtherFile.Text = "是否复制处理路径下的其它非图片文件"; 324 | this.chbCopyOtherFile.UseVisualStyleBackColor = true; 325 | // 326 | // cmbQuality 327 | // 328 | this.cmbQuality.FormattingEnabled = true; 329 | this.cmbQuality.Location = new System.Drawing.Point(184, 127); 330 | this.cmbQuality.Name = "cmbQuality"; 331 | this.cmbQuality.Size = new System.Drawing.Size(57, 20); 332 | this.cmbQuality.TabIndex = 27; 333 | // 334 | // label4 335 | // 336 | this.label4.AutoSize = true; 337 | this.label4.Location = new System.Drawing.Point(11, 130); 338 | this.label4.Name = "label4"; 339 | this.label4.Size = new System.Drawing.Size(167, 12); 340 | this.label4.TabIndex = 28; 341 | this.label4.Text = "压缩质量(1(最差)-100(最好))"; 342 | // 343 | // label6 344 | // 345 | this.label6.AutoSize = true; 346 | this.label6.Location = new System.Drawing.Point(268, 127); 347 | this.label6.Name = "label6"; 348 | this.label6.Size = new System.Drawing.Size(59, 12); 349 | this.label6.TabIndex = 29; 350 | this.label6.Text = "压缩高度:"; 351 | // 352 | // label9 353 | // 354 | this.label9.AutoSize = true; 355 | this.label9.Location = new System.Drawing.Point(381, 127); 356 | this.label9.Name = "label9"; 357 | this.label9.Size = new System.Drawing.Size(59, 12); 358 | this.label9.TabIndex = 30; 359 | this.label9.Text = "压缩宽度:"; 360 | // 361 | // txtCompressHeight 362 | // 363 | this.txtCompressHeight.Location = new System.Drawing.Point(327, 124); 364 | this.txtCompressHeight.Name = "txtCompressHeight"; 365 | this.txtCompressHeight.Size = new System.Drawing.Size(48, 21); 366 | this.txtCompressHeight.TabIndex = 31; 367 | this.txtCompressHeight.Text = "0"; 368 | // 369 | // txtCompressWidth 370 | // 371 | this.txtCompressWidth.Location = new System.Drawing.Point(446, 121); 372 | this.txtCompressWidth.Name = "txtCompressWidth"; 373 | this.txtCompressWidth.Size = new System.Drawing.Size(48, 21); 374 | this.txtCompressWidth.TabIndex = 32; 375 | this.txtCompressWidth.Text = "0"; 376 | // 377 | // label5 378 | // 379 | this.label5.AutoSize = true; 380 | this.label5.Location = new System.Drawing.Point(6, 82); 381 | this.label5.Name = "label5"; 382 | this.label5.Size = new System.Drawing.Size(137, 12); 383 | this.label5.TabIndex = 12; 384 | this.label5.Text = "处理路径格式明细输出:"; 385 | // 386 | // label10 387 | // 388 | this.label10.AutoSize = true; 389 | this.label10.Location = new System.Drawing.Point(268, 148); 390 | this.label10.Name = "label10"; 391 | this.label10.Size = new System.Drawing.Size(209, 12); 392 | this.label10.TabIndex = 33; 393 | this.label10.Text = "注:压缩高度宽度为0默认为原图片宽高"; 394 | // 395 | // Form1 396 | // 397 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 398 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 399 | this.ClientSize = new System.Drawing.Size(1019, 428); 400 | this.Controls.Add(this.label10); 401 | this.Controls.Add(this.txtCompressWidth); 402 | this.Controls.Add(this.txtCompressHeight); 403 | this.Controls.Add(this.label9); 404 | this.Controls.Add(this.label6); 405 | this.Controls.Add(this.label4); 406 | this.Controls.Add(this.cmbQuality); 407 | this.Controls.Add(this.chbCopyOtherFile); 408 | this.Controls.Add(this.label3); 409 | this.Controls.Add(this.txtMaxTask); 410 | this.Controls.Add(this.ChbIsSubFolder); 411 | this.Controls.Add(this.label8); 412 | this.Controls.Add(this.lbTime); 413 | this.Controls.Add(this.lbDealing); 414 | this.Controls.Add(this.groupBox2); 415 | this.Controls.Add(this.label7); 416 | this.Controls.Add(this.txtLeastCount); 417 | this.Controls.Add(this.groupBox1); 418 | this.Controls.Add(this.btnOutPath); 419 | this.Controls.Add(this.txtOutPath); 420 | this.Controls.Add(this.label2); 421 | this.Controls.Add(this.label1); 422 | this.Controls.Add(this.btnPath); 423 | this.Controls.Add(this.txtPath); 424 | this.Controls.Add(this.btnStop); 425 | this.Controls.Add(this.lstLog); 426 | this.Controls.Add(this.btnStart); 427 | this.Name = "Form1"; 428 | this.Text = "你定图片压缩工具"; 429 | this.Load += new System.EventHandler(this.Form1_Load); 430 | this.groupBox1.ResumeLayout(false); 431 | this.groupBox1.PerformLayout(); 432 | this.groupBox2.ResumeLayout(false); 433 | this.ResumeLayout(false); 434 | this.PerformLayout(); 435 | 436 | } 437 | 438 | #endregion 439 | 440 | private System.Windows.Forms.Button btnStart; 441 | private System.Windows.Forms.ListBox lstLog; 442 | private System.Windows.Forms.Button btnStop; 443 | private System.Windows.Forms.TextBox txtPath; 444 | private System.Windows.Forms.Button btnPath; 445 | private System.Windows.Forms.Label label1; 446 | private System.Windows.Forms.Label label2; 447 | private System.Windows.Forms.TextBox txtOutPath; 448 | private System.Windows.Forms.Button btnOutPath; 449 | private System.Windows.Forms.GroupBox groupBox1; 450 | private System.Windows.Forms.Label lbFolderCount; 451 | private System.Windows.Forms.Label lbOutPath; 452 | private System.Windows.Forms.Label lbDealPath; 453 | private System.Windows.Forms.Label lbFileCount; 454 | private System.Windows.Forms.TextBox txtLeastCount; 455 | private System.Windows.Forms.Label label7; 456 | private System.Windows.Forms.GroupBox groupBox2; 457 | private System.Windows.Forms.Label lbDealing; 458 | private System.Windows.Forms.ListBox lsbResult; 459 | private System.Windows.Forms.Label lbTime; 460 | private System.Windows.Forms.Timer timer1; 461 | private System.Windows.Forms.Label label8; 462 | private System.Windows.Forms.CheckBox ChbIsSubFolder; 463 | private System.Windows.Forms.Label label3; 464 | private System.Windows.Forms.TextBox txtMaxTask; 465 | private System.Windows.Forms.ListBox lstDetail; 466 | private System.Windows.Forms.CheckBox chbCopyOtherFile; 467 | private System.Windows.Forms.ComboBox cmbQuality; 468 | private System.Windows.Forms.Label label4; 469 | private System.Windows.Forms.Label label6; 470 | private System.Windows.Forms.Label label9; 471 | private System.Windows.Forms.TextBox txtCompressHeight; 472 | private System.Windows.Forms.TextBox txtCompressWidth; 473 | private System.Windows.Forms.Label label5; 474 | private System.Windows.Forms.Label label10; 475 | } 476 | } 477 | 478 | --------------------------------------------------------------------------------