-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmap.cpp
More file actions
38 lines (29 loc) · 855 Bytes
/
Bitmap.cpp
File metadata and controls
38 lines (29 loc) · 855 Bytes
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
#include "Bitmap.h"
#include <stdio.h>
Bitmap::Bitmap(char* filename) {
FILE* file = fopen(filename, "r");
fread(&header, sizeof(Header), 1, file);
int numOfPixels = header.width * header.height;
pixels = new int[numOfPixels];
fread(pixels, sizeof(int), numOfPixels, file);
fclose(file);
}
Bitmap::Bitmap(int width, int height) {
this->width = width;
this->height = height;
header.width = width;
header.height = -height;
int pSize = width*height;
header.sizeOfBMPData = 4*pSize;
header.fileSize = header.sizeOfBMPData + (14+header.dibSize);
pixels = new int[pSize];
}
Bitmap::~Bitmap() {
delete[] pixels;
}
void Bitmap::write(const char* filename) {
FILE* file = fopen(filename, "wb");
fwrite(&header, 1, sizeof(Header), file);
fwrite(pixels, 1, header.sizeOfBMPData, file);
fclose(file);
}