-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.cpp
73 lines (60 loc) · 1.66 KB
/
demo2.cpp
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
// Program: demo2.cpp
// Purpose: Demonstrate use of bmplip for handling
// bmp colored and grayscale images
// Program load a gray image and store in another file
// Author: Mohammad El-Ramly
// Date: 30 March 2018
// Version: 1.0
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include "bmplib.cpp"
using namespace std;
unsigned char image[SIZE][SIZE];
void loadImage ();
void saveImage ();
void doSomethingForImage ();
int main()
{
loadImage();
doSomethingForImage();
saveImage();
return 0;
}
//_________________________________________
void loadImage () {
char imageFileName[100];
// Get gray scale image file name
cout << "Enter the source image file name: ";
cin >> imageFileName;
// Add to it .bmp extension and load image
strcat (imageFileName, ".bmp");
readGSBMP(imageFileName, image);
}
//_________________________________________
void saveImage () {
char imageFileName[100];
// Get gray scale image target file name
cout << "Enter the target image file name: ";
cin >> imageFileName;
// Add to it .bmp extension and load image
strcat (imageFileName, ".bmp");
writeGSBMP(imageFileName, image);
}
//_________________________________________
void doSomethingForImage() {
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j< SIZE; j++) {
/* Example code to convert to BW the image
A better version should NOt use 127 but the
average of the pixels
if (image[i][j] > 127)
image[i][j] = 255;
else
image[i][j] = 0;
*/
// do something with the image
}
}
}