年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.8 KiB

4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kingo.Plugin.RasterToKOTilesApp.KoDataBase
{
class PngQuant
{
public static void Run(Bitmap bitmap, MemoryStream ms, string path)
{
//string path = AppDomain.CurrentDomain.BaseDirectory + @"pngquant\pngquant.exe";
Process process = new Process();
process.StartInfo.FileName = path;
process.StartInfo.Arguments = "256 --quality=20-30 -";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
//process.OutputDataReceived += Process_OutputDataReceived;
//process.ErrorDataReceived += Process_ErrorDataReceived;
process.Start();
//process.BeginErrorReadLine();
//process.BeginOutputReadLine();
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Png);
//stream.CopyTo(process.StandardInput.BaseStream);
process.StandardInput.BaseStream.Write(stream.ToArray(), 0, Convert.ToInt32(stream.Length));
process.StandardInput.Close();
}
process.StandardOutput.BaseStream.CopyTo(ms);
string o = process.StandardOutput.ReadToEnd();
string e = process.StandardError.ReadToEnd();
process.WaitForExit();
if (process != null)
{
process.Close();
}
}
}
}