Last week I received an invitation for a social work meeting about "Pixel art in spreadsheets".
I thought: "How hard can it be".
Well, it is about 25 lines of C# 9.0 hard! 😁
Last week I received an invitation for a social work meeting about “Pixel art in spreadsheets”.
I thought: “How hard can it be?” .
Well, it is about 25 lines of C# 9.0 hard! 😀
The code
Using my past experience with EmguCV (OpenCV for .NET)
and EPPlus (Excel spreadsheets for .NET), it was quickly built.
if ( ! File . Exists ( source ))
throw new FileNotFoundException ( $"Input image not found" , source );
var sourceImage = CvInvoke . Imread ( source );
. ResizeForFrame ( sourceImage , mat , new Size ( 64 , 64 ), Inter . Lanczos4 , 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 ( var y = 1 ; y <= image . Height ; y ++ )
worksheet . Row ( y ). Height = 27.5 ;
for ( var x = 1 ; x <= image . Width ; x ++ )
worksheet . Column ( x ). Width = 5 ;
worksheet . Cells [ y , x ]. Style . Fill . PatternType = ExcelFillStyle . Solid ;
worksheet . Cells [ y , x ]. Style . Fill . BackgroundColor . SetColor (
Added wrapping for readability.
The result
Demonstration of the Pixcel app.
The source
Liking the result, I christened the project Pixcel and shared the code on GitHub .