-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwrite_bitmap.cpp
36 lines (31 loc) · 884 Bytes
/
write_bitmap.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
#include "BitmapPlusPlus.hpp"
#include <random>
#include <filesystem>
#include <iostream>
static bmp::Pixel random_color() {
static std::random_device seed{};
static std::default_random_engine engine{seed()};
std::uniform_int_distribution<std::int32_t> dist(0, 255);
bmp::Pixel color{};
color.r = dist(engine);
color.g = dist(engine);
color.b = dist(engine);
return color;
}
int main() {
try {
// Create a 512x512 bitmap
bmp::Bitmap image(512, 512);
// Assign a random color to each pixel in the image
for (bmp::Pixel &pixel: image) {
pixel = random_color();
}
// Save bitmap to new file image.bmp
image.save(std::filesystem::path(BIN_DIR) / "image.bmp");
// And Voila!
return EXIT_SUCCESS;
} catch (const bmp::Exception &e) {
std::cerr << "[BMP ERROR]: " << e.what() << std::endl;
return EXIT_FAILURE;
}
}