forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
33 lines (28 loc) · 966 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// Copyright (c) 2022 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
var imageFilePath = args[0];
using var image = Image.Load<Rgba32>(imageFilePath);
image.Mutate(x => x.Resize(new Size(84, 48)));
image.Mutate(x => x.BlackWhite());
var colWhite = new Rgba32(255, 255, 255);
var width = 84;
var result = new byte[504];
for (var pos = 0; pos < result.Length; pos++)
{
byte toStore = 0;
for (int bit = 0; bit < 8; bit++)
{
var x = pos % width;
var y = pos / width * 8 + bit;
toStore = (byte)(toStore | ((image[x, y] == colWhite ? 0 : 1) << bit));
}
result[pos] = toStore;
}
var resultString = $"var bitmap = new byte[] {{{String.Join(",", result.Select(b => $"0x{b.ToString("X2")}"))}}}";
Console.WriteLine(resultString);
Console.ReadKey();