.net core 使用Pngquant进行PNG图片压缩

上传者: 29793333 | 上传时间: 2021-04-29 01:38:23 | 文件大小: 64KB | 文件类型: RAR
在Startup.cs文件中配置Pngquant所在路径 public void ConfigureServices(IServiceCollection services) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var pngquant = Configuration.GetSection("PngquantPathLinux").Value; PngquantConfig.Configure(new PngquantOptions { BinaryFolder = pngquant }); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var pngquant = Configuration.GetSection("PngquantPathWin").Value; PngquantConfig.Configure(new PngquantOptions { BinaryFolder = pngquant }); } } 使用: FileStream fs = new FileStream(filePath, FileMode.Open); byte[] byData = new byte[fs.Length]; //设置压缩选项 var options = new PngQuantOptions() { QualityMinMax = (65, 80), //Minimum = 65, Maximum = 80. Default null Speed = 1, //Value between 1 and 11. default 3. IEBug = false, //Attempt to fix iebug. default false. Bit = 256 //bit-rate. default 256 }; ///Invoke the compressor Compressor pngQuant = new PngQuant(options); //Compress bytes byte[] compressed = await pngQuant.Compress(byData); MemoryStream ms = new MemoryStream(compressed); //把那个byte[] 数组传进去, 然后 using (FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.Write)) ms.WriteTo(fs);

文件下载

资源详情

[{"title":"( 22 个子文件 64KB ) .net core 使用Pngquant进行PNG图片压缩","children":[{"title":"Com.macao.electron.Pngquant","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"netcoreapp3.1","children":[{"title":"Com.macao.electron.Pngquant.dll <span style='color:#111;'> 11.50KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.pdb <span style='color:#111;'> 11.57KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.deps.json <span style='color:#111;'> 55.79KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":"obj","children":[{"title":"project.nuget.cache <span style='color:#111;'> 11.16KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.csproj.nuget.dgspec.json <span style='color:#111;'> 2.72KB </span>","children":null,"spread":false},{"title":"project.assets.json <span style='color:#111;'> 205.69KB </span>","children":null,"spread":false},{"title":"Debug","children":[{"title":"netcoreapp3.1","children":[{"title":"Com.macao.electron.Pngquant.dll <span style='color:#111;'> 11.50KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.AssemblyInfoInputs.cache <span style='color:#111;'> 42B </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.pdb <span style='color:#111;'> 11.57KB </span>","children":null,"spread":false},{"title":".NETCoreApp,Version=v3.1.AssemblyAttributes.cs <span style='color:#111;'> 190B </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.AssemblyInfo.cs <span style='color:#111;'> 1.04KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.assets.cache <span style='color:#111;'> 32.69KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.csproj.FileListAbsolute.txt <span style='color:#111;'> 1.30KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.csprojAssemblyReference.cache <span style='color:#111;'> 2.43KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.csproj.CoreCompileInputs.cache <span style='color:#111;'> 42B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"Com.macao.electron.Pngquant.csproj.nuget.g.targets <span style='color:#111;'> 294B </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.csproj.nuget.g.props <span style='color:#111;'> 1.37KB </span>","children":null,"spread":false}],"spread":true},{"title":"Compressor.cs <span style='color:#111;'> 710B </span>","children":null,"spread":false},{"title":"PngquantConfig.cs <span style='color:#111;'> 1.34KB </span>","children":null,"spread":false},{"title":"JpegOptimOptions.cs <span style='color:#111;'> 1.87KB </span>","children":null,"spread":false},{"title":"Com.macao.electron.Pngquant.csproj <span style='color:#111;'> 311B </span>","children":null,"spread":false},{"title":"PngQuantOptions.cs <span style='color:#111;'> 3.18KB </span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明