-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
55 lines (46 loc) · 2.29 KB
/
Copy pathexample.cpp
File metadata and controls
55 lines (46 loc) · 2.29 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
#include <iostream>
#include <fstream>
// Example of how to use the generated hex arrays
// This would be generated by: cpphexconv -o resources.h image.png font.ttf
// Example hex array (this would be generated by the tool)
const unsigned char example_png_hex[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
0x61, 0x00, 0x00, 0x00, 0x19, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x60, 0x18, 0x05, 0xa3,
0x60, 0x14, 0x8c, 0x82, 0x51, 0x30, 0x0a, 0x46, 0xc1, 0x28, 0x18, 0x05, 0x00, 0x00, 0x00, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned int example_png_hex_size = 64;
// Function to save hex array back to a file
void saveHexToFile(const unsigned char* data, unsigned int size, const std::string& filename) {
std::ofstream file(filename, std::ios::binary);
if (file.is_open()) {
file.write(reinterpret_cast<const char*>(data), size);
file.close();
std::cout << "Saved " << size << " bytes to " << filename << std::endl;
} else {
std::cerr << "Failed to open file: " << filename << std::endl;
}
}
// Function to display hex array info
void displayHexInfo(const unsigned char* data, unsigned int size, const std::string& name) {
std::cout << "Array: " << name << std::endl;
std::cout << "Size: " << size << " bytes" << std::endl;
std::cout << "First 16 bytes: ";
for (unsigned int i = 0; i < std::min(size, 16u); i++) {
printf("%02x ", data[i]);
}
std::cout << std::endl << std::endl;
}
int main() {
std::cout << "C++ Hex Array Usage Example" << std::endl;
std::cout << "===========================" << std::endl << std::endl;
// Display information about the embedded data
displayHexInfo(example_png_hex, example_png_hex_size, "example_png_hex");
// Save the hex array back to a file (useful for testing)
saveHexToFile(example_png_hex, example_png_hex_size, "restored_example.png");
// You can also use the data directly in your application
// For example, with a graphics library:
// loadImageFromMemory(example_png_hex, example_png_hex_size);
return 0;
}