- 1 year ago
Showing a screenshot in a newly created window in C++
Comment
1 / 1
To show a screenshot in a newly created window in C++, you can use the OpenCV library. Here's an example code snippet:
cpp#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
// Capture the screenshot
cv::Mat screenshot = cv::imread("screenshot.jpg", cv::IMREAD_COLOR);
// Create a new window to display the screenshot
cv::namedWindow("Screenshot", cv::WINDOW_NORMAL);
// Show the screenshot in the new window
cv::imshow("Screenshot", screenshot);
// Wait for a key press before closing the window
cv::waitKey(0);
// Close the window
cv::destroyWindow("Screenshot");
return 0;
}
In this example, we first use the cv::imread()
function to read the screenshot image file into a cv::Mat
object. Then, we create a new window using the cv::namedWindow()
function and show the screenshot in the new window using the cv::imshow()
function. Finally, we wait for a key press using the cv::waitKey()
function, and then close the window using the cv::destroyWindow()
function.
Note that you'll need to have the OpenCV library installed and configured in your C++ development environment to use this code.