-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenGrabberTest.cpp
More file actions
45 lines (41 loc) · 1.25 KB
/
ScreenGrabberTest.cpp
File metadata and controls
45 lines (41 loc) · 1.25 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
#include "MonitorInfo.h"
#include "ScreenGrabber.h"
#include <cassert>
#include <fstream>
#include <iostream>
int main() {
CScreenGrabber screenGrabber = {};
assert(screenGrabber.SetEncoder(L"image/jpeg"));
ULONG quality = 15;
screenGrabber.SetEncoderParameters({
.Count = 1,
.Parameter = {
[0] = {
.Guid = Gdiplus::EncoderQuality,
.NumberOfValues = 1,
.Type = Gdiplus::EncoderParameterValueTypeLong,
.Value = &quality
}
}
});
std::vector<SMonitorInfo> allMonitors = GetAllMonitorsInfo();
assert(allMonitors.size() > 0);
for (size_t i = 0; i < allMonitors.size(); ++i) {
auto& monitor = allMonitors[i];
std::optional<std::vector<uint8_t>> result = screenGrabber.ScreenCapture(monitor);
if (result.has_value()) {
std::string filename = std::to_string(i) + ".jpg";
std::ofstream outputFile(filename, std::ios::binary);
if (outputFile.is_open()) {
outputFile.write((const char*)result->data(), result->size());
outputFile.close();
std::cout << "Image captured from monitor " << i << " and saved as " << filename << std::endl;
} else {
std::cerr << "Failed to create file: " << filename << std::endl;
}
} else {
std::cerr << "Failed to capture screen for monitor " << i << std::endl;
}
}
return 0;
}