diff --git a/.gitignore b/.gitignore index 4ce6fdd..fba305e 100644 --- a/.gitignore +++ b/.gitignore @@ -337,4 +337,7 @@ ASALocalRun/ .localhistory/ # BeatPulse healthcheck temp database -healthchecksdb \ No newline at end of file +healthchecksdb + +# Pixcel +launchSettings.json diff --git a/Pixcel/Pixcel.csproj b/Pixcel/Pixcel.csproj index 2d8e1de..bcb0a4a 100644 --- a/Pixcel/Pixcel.csproj +++ b/Pixcel/Pixcel.csproj @@ -14,6 +14,7 @@ + diff --git a/Pixcel/Program.cs b/Pixcel/Program.cs index fa1118f..d222c63 100644 --- a/Pixcel/Program.cs +++ b/Pixcel/Program.cs @@ -1,27 +1,32 @@ -using OfficeOpenXml; +using Emgu.CV; +using Emgu.CV.CvEnum; +using Emgu.CV.Structure; +using OfficeOpenXml; using OfficeOpenXml.Style; using System.Drawing; using System.IO; var source = args[0]; +if (!File.Exists(source)) throw new FileNotFoundException($"Input image not found", source); -var bitmap = new Bitmap(64, 64); -using var graphics = Graphics.FromImage(bitmap); -graphics.DrawImage(new Bitmap(source), 0, 0, 64, 64); +var sourceImage = CvInvoke.Imread(source); +var mat = new Mat(); +CvInvoke.ResizeForFrame(sourceImage, mat, new Size(64, 64), Inter.Lanczos4, scaleDownOnly: true); +var image = mat.ToImage(); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using var package = new ExcelPackage(new FileInfo(source.Replace(Path.GetExtension(source), ".xlsx"))); var worksheet = package.Workbook.Worksheets["Pixcel"] ?? package.Workbook.Worksheets.Add("Pixcel"); -for (int y = 1; y <= bitmap.Width; y++) +for (int y = 1; y <= image.Height; y++) { - worksheet.Column(y).Width = 5; + worksheet.Row(y).Height = 27.5; - for (int x = 1; x <= bitmap.Height; x++) + for (int x = 1; x <= image.Width; x++) { - worksheet.Row(x).Height = 27.5; - worksheet.Cells[x, y].Style.Fill.PatternType = ExcelFillStyle.Solid; - worksheet.Cells[x, y].Style.Fill.BackgroundColor.SetColor(bitmap.GetPixel(y - 1, x - 1)); + worksheet.Column(x).Width = 5; + worksheet.Cells[y, x].Style.Fill.PatternType = ExcelFillStyle.Solid; + worksheet.Cells[y, x].Style.Fill.BackgroundColor.SetColor(0, image.Data[y-1, x-1, 2], image.Data[y-1, x-1, 1], image.Data[y-1, x-1, 0]); } }