-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonochromeBitmap.cs
More file actions
67 lines (59 loc) · 1.96 KB
/
MonochromeBitmap.cs
File metadata and controls
67 lines (59 loc) · 1.96 KB
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
64
65
66
67
using System;
using System.IO;
namespace BmpInspector
{
class MonochromeBitmap
{
public byte[] image_data;
public byte[] signature = new byte[2];
public byte[] file_size = new byte[4];
public byte[] reserved = new byte[4];
public byte[] data_offset = new byte[4];
public byte[] size = new byte[4];
public byte[] width = new byte[4];
public byte[] height = new byte[4];
public byte[] planes = new byte[2];
public byte[] bits_per_pixel = new byte[2];
public byte[] compression = new byte[4];
public byte[] image_size = new byte[4];
public byte[] xPixelsPerM = new byte[4];
public byte[] yPixelsPerM = new byte[4];
public byte[] colors_used = new byte[4];
public byte[] important_colors = new byte[4];
public byte[] color_table;
public byte[] pixel_data;
public MonochromeBitmap(byte[] source_image) {
this.image_data = source_image;
ProcessImageData();
}
public MonochromeBitmap(string path) {
this.image_data = File.ReadAllBytes(path);
ProcessImageData();
}
private void ProcessImageData() {
this.signature = this.image_data[0..2];
this.file_size = this.image_data[2..6];
this.reserved = this.image_data[6..10];
this.data_offset = this.image_data[10..14];
this.size = this.image_data[14..18];
this.width = this.image_data[18..22];
this.height = this.image_data[22..26];
this.planes = this.image_data[26..28];
this.bits_per_pixel = this.image_data[28..30];
this.compression = this.image_data[30..34];
this.image_size = this.image_data[34..38];
this.xPixelsPerM = this.image_data[38..42];
this.yPixelsPerM = this.image_data[42..46];
this.colors_used = this.image_data[46..50];
this.important_colors = this.image_data[50..54];
if(this.colors_used[0] == 0x00) {
Console.WriteLine("Monochrome Image");
this.color_table = this.image_data[54..62];
this.pixel_data = this.image_data[62..];
}
else {
Console.WriteLine("This bitmap is not a monochrome image.");
}
}
}
}