-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawer.cs
63 lines (54 loc) · 1.63 KB
/
Drawer.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Drawing;
using System.IO;
namespace BinaryCodeToImageConverter
{
public class Drawer
{
private Bitmap Image;
public Drawer(Bitmap image)
{
Image = image;
}
public void DrawToBitmap(string sourcePath)
{
byte[] fileSource = File.ReadAllBytes(sourcePath);
Color[] Colors = new Color[fileSource.Length];
int lastFileSourceElement = fileSource.Length - 1;
byte r, g, b, a;
for(int i = 0; i < Colors.Length; i++)
{
r = g = b = a = 0;
if(i + 3 < lastFileSourceElement)
{
r = fileSource[i + 3];
}
if(i + 2 < lastFileSourceElement)
{
g = fileSource[i + 2];
}
if(i + 1 < lastFileSourceElement)
{
b = fileSource[i + 1];
}
if(i < lastFileSourceElement)
{
a = fileSource[i];
}
Colors[i] = Color.FromArgb(((a << 24) | (r << 16) | (g << 8) | b));
}
for(int y = 0; y < Image.Height; y++)
{
for(int x = 0; x < Image.Width; x++)
{
if(x * Image.Width + y < Colors.Length)
{
Image.SetPixel(x, y, Colors[x * Image.Width + y]);
continue;
}
Image.SetPixel(x, y, Color.White);
}
}
}
}
}