Skip to content

Commit

Permalink
Support non-square images
Browse files Browse the repository at this point in the history
  • Loading branch information
eNeRGy164 committed Feb 8, 2021
1 parent d67229b commit 301e298
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,7 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb

# Pixcel
launchSettings.json
1 change: 1 addition & 0 deletions Pixcel/Pixcel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Emgu.CV.runtime.windows" Version="4.5.1.4349" />
<PackageReference Include="EPPlus" Version="5.5.3" />
</ItemGroup>

Expand Down
25 changes: 15 additions & 10 deletions Pixcel/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Bgr, byte>();

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]);
}
}

Expand Down

0 comments on commit 301e298

Please sign in to comment.