-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBitmapInfoHeader.cs
More file actions
217 lines (182 loc) · 7.44 KB
/
BitmapInfoHeader.cs
File metadata and controls
217 lines (182 loc) · 7.44 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.MemoryMappedFiles;
namespace RoboNav
{
class BitmapInfoHeader
{
public int BitmapWidth { get; set; }
public int BitmapHeight { get; set; }
public short ColorPlanes { set; get; }
public short BitsPerPixel { set; get; }
public int CompressinoMethod { set; get; }
public int ColorDataSize { set; get; }
public int HorizantalResolution { set; get; }
public int VerticalResolution { set; get; }
public int Colors { set; get; }
public int IColors { set; get; }
public BitmapInfoHeader()
{
CompressinoMethod = 0;
ColorDataSize = 0;
ColorPlanes = 1;
}
public byte[] CreateInfoHeaderData(int ColorDataSize)
{
this.ColorDataSize = ColorDataSize;
using (var s = new MemoryStream())
using (var writer = new BinaryWriter(s))
{
//writer.Write(HeaderSize);
writer.Write(BitmapWidth);
writer.Write(BitmapHeight);
writer.Write(ColorPlanes);
writer.Write(BitsPerPixel);
writer.Write(CompressinoMethod);
writer.Write(ColorDataSize);
writer.Write(HorizantalResolution);
writer.Write(VerticalResolution);
writer.Write(Colors);
writer.Write(IColors);
return s.ToArray();
}
}
public static BitmapInfoHeader GetInfoHeader(byte[] data)
{
using (var s = new MemoryStream(data))
using (var reader = new BinaryReader(s))
{
var header = new BitmapInfoHeader();
// HeaderSize = reader.ReadInt32(),
header.BitmapWidth = reader.ReadInt32();
header.BitmapHeight = reader.ReadInt32();
header.ColorPlanes = reader.ReadInt16();
header.BitsPerPixel = reader.ReadInt16();
header.CompressinoMethod = reader.ReadInt32();
header.ColorDataSize = reader.ReadInt32();
header.HorizantalResolution = reader.ReadInt32();
header.VerticalResolution = reader.ReadInt32();
header.Colors = reader.ReadInt32();
header.IColors = reader.ReadInt32();
return header;
}
}
public static BitmapInfoHeader GetInfoHeader(MemoryMappedViewAccessor Reader, out long MMPosition)
{
MMPosition = 18;
var header = new BitmapInfoHeader();
// HeaderSize = reader.ReadInt32(),
header.BitmapWidth = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.BitmapHeight = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.ColorPlanes = Reader.ReadInt16(MMPosition);
MMPosition += 2;
header.BitsPerPixel = Reader.ReadInt16(MMPosition);
MMPosition += 2;
header.CompressinoMethod = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.ColorDataSize = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.HorizantalResolution = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.VerticalResolution = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.Colors = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.IColors = Reader.ReadInt32(MMPosition);
MMPosition += 4;
return header;
}
}
class BigBitmapInfoHeader
{
public long BitmapWidth { get; set; }
public long BitmapHeight { get; set; }
public short ColorPlanes { set; get; }
public short BitsPerPixel { set; get; }
public int CompressinoMethod { set; get; }
public long ColorDataSize { set; get; }
public int HorizantalResolution { set; get; }
public int VerticalResolution { set; get; }
public int Colors { set; get; }
public int IColors { set; get; }
public BigBitmapInfoHeader()
{
CompressinoMethod = 0;
ColorDataSize = 0;
ColorPlanes = 1;
}
public byte[] CreateInfoHeaderData(long ColorDataSize)
{
using (var s = new MemoryStream())
using (var writer = new BinaryWriter(s))
{
//writer.Write(HeaderSize);
writer.Write(BitmapWidth);
writer.Write(BitmapHeight);
writer.Write(ColorPlanes);
writer.Write(BitsPerPixel);
writer.Write(CompressinoMethod);
this.ColorDataSize = ColorDataSize;
writer.Write(ColorDataSize);
writer.Write(HorizantalResolution);
writer.Write(VerticalResolution);
writer.Write(Colors);
writer.Write(IColors);
return s.ToArray();
}
}
public static BigBitmapInfoHeader GetInfoHeader(byte[] data)
{
using (var s = new MemoryStream(data))
using (var reader = new BinaryReader(s))
{
return new BigBitmapInfoHeader
{
// HeaderSize = reader.ReadInt32(),
BitmapWidth = reader.ReadInt64(),
BitmapHeight = reader.ReadInt64(),
ColorPlanes = reader.ReadInt16(),
BitsPerPixel = reader.ReadInt16(),
CompressinoMethod = reader.ReadInt32(),
ColorDataSize = reader.ReadInt64(),
HorizantalResolution = reader.ReadInt32(),
VerticalResolution = reader.ReadInt32(),
Colors = reader.ReadInt32(),
IColors = reader.ReadInt32()
};
}
}
public static BigBitmapInfoHeader GetInfoHeader(MemoryMappedViewAccessor Reader, ref int MMPosition)
{
//MMPosition = 18;
var header = new BigBitmapInfoHeader();
// HeaderSize = reader.ReadInt32(),
header.BitmapWidth = Reader.ReadInt64(MMPosition);
MMPosition += 8;
header.BitmapHeight = Reader.ReadInt64(MMPosition);
MMPosition += 8;
header.ColorPlanes = Reader.ReadInt16(MMPosition);
MMPosition += 2;
header.BitsPerPixel = Reader.ReadInt16(MMPosition);
MMPosition += 2;
header.CompressinoMethod = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.ColorDataSize = Reader.ReadInt64(MMPosition);
MMPosition += 8;
header.HorizantalResolution = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.VerticalResolution = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.Colors = Reader.ReadInt32(MMPosition);
MMPosition += 4;
header.IColors = Reader.ReadInt32(MMPosition);
MMPosition += 4;
return header;
}
}
}