https://github.com/nir3x/screengrabber.cpp
ScreenGrabber.cpp - Library for Capturing Screens on Windows Systems
https://github.com/nir3x/screengrabber.cpp
c-plus-plus cpp gdi-plus image-encoder image-processing monitor-information screen-capture windows-api
Last synced: 3 months ago
JSON representation
ScreenGrabber.cpp - Library for Capturing Screens on Windows Systems
- Host: GitHub
- URL: https://github.com/nir3x/screengrabber.cpp
- Owner: NIR3X
- License: agpl-3.0
- Created: 2024-02-13T23:27:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-18T22:02:40.000Z (over 1 year ago)
- Last Synced: 2024-02-19T22:38:51.864Z (over 1 year ago)
- Topics: c-plus-plus, cpp, gdi-plus, image-encoder, image-processing, monitor-information, screen-capture, windows-api
- Language: C++
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ScreenGrabber.cpp - Library for Capturing Screens on Windows Systems
The **ScreenGrabber** library provides functionality to capture screens or specific regions of the screen on Windows systems and save them as images. It supports various image formats, including BMP, GIF, JPEG, PNG, and TIFF, through the GDI+ library.
## Features
* Capture the entire screen or specific regions.
* Supports capturing multiple monitors.
* Save captured screens in BMP, GIF, JPEG, PNG, or TIFF formats with customizable options.
* Easy-to-use interface.## Installation
To use the **ScreenGrabber** library in your project, follow these steps:
1. Clone this repository and compile it using a C++ compiler:
```bash
git clone https://github.com/NIR3X/ScreenGrabber.cpp
cd ScreenGrabber.cpp
make
```2. Include the necessary header file `ScreenGrabber.h` in your project.
3. Link against the `ScreenGrabber.a` static library.
4. Ensure that your project is linked against the following libraries:
* `gdi32`
* `gdiplus`
* `ole32`
* `shcore`## Usage
Here's a simple example demonstrating how to capture screens using the **ScreenGrabber** library:
```cpp
#include "ScreenGrabber.h"
#include
#includeint main() {
// Create an instance of CScreenGrabber
CScreenGrabber screenGrabber = {};// Set the encoder to the desired format (e.g., JPEG)
std::wstring mimeType = L"image/jpeg";
screenGrabber.SetEncoder(mimeType);// Set JPEG quality
ULONG quality = 15;
screenGrabber.SetEncoderParameters({
.Count = 1,
.Parameter = {
[0] = {
.Guid = Gdiplus::EncoderQuality,
.NumberOfValues = 1,
.Type = Gdiplus::EncoderParameterValueTypeLong,
.Value = &quality
}
}
});// Get information about all monitors
std::vector allMonitors = GetAllMonitorsInfo();// Capture screens for each monitor
for (size_t i = 0; i < allMonitors.size(); ++i) {
auto& monitor = allMonitors[i];
std::optional> result = screenGrabber.ScreenCapture(monitor);
if (result.has_value()) {
// Save captured image to file
std::string filename = std::to_string(i) + ".jpg"; // Change extension based on encoder
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;
}
```## License
[](https://www.gnu.org/licenses/agpl-3.0.html)
This program is Free Software: You can use, study share and improve it at your
will. Specifically you can redistribute and/or modify it under the terms of the
[GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) as
published by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.