Created
August 4, 2016 12:50
-
-
Save maaatts/e33d45eaae246e471ceb7af278bb6322 to your computer and use it in GitHub Desktop.
win32 stinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Screenshot.hpp" | |
Screenshot::Screenshot(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) | |
{ | |
HBITMAP hBitmap; | |
hdcSys = GetDC(NULL); | |
hdcMem = CreateCompatibleDC(hdcSys); | |
void *ptrBitmapPixels; | |
BITMAPINFO bi; HDC hdc; | |
ZeroMemory(&bi, sizeof(BITMAPINFO)); | |
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
bi.bmiHeader.biWidth = getWidth(); | |
bi.bmiHeader.biHeight = -getHeight(); | |
bi.bmiHeader.biPlanes = 1; | |
bi.bmiHeader.biBitCount = 32; | |
hdc = GetDC(NULL); | |
hBitmap = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &ptrBitmapPixels, NULL, 0); | |
SelectObject(hdcMem, hBitmap); | |
this->mat = cv::Mat(getHeight(), getWidth(), CV_8UC4, ptrBitmapPixels, 0); | |
} | |
Screenshot::~Screenshot() | |
{ | |
// TODO: dtor() | |
} | |
cv::Mat Screenshot::getMat() | |
{ | |
BitBlt(hdcMem, this->getX(), this->getY(), this->getWidth(), this->getHeight(), hdcSys, 0, 0, SRCCOPY); | |
return this->mat; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <opencv2/core.hpp> | |
#include <Windows.h> | |
class Screenshot { | |
private: | |
HDC hdcSys, hdcMem; | |
int x, y, width, height; | |
cv::Mat mat; | |
public: | |
Screenshot(int x, int y, int w, int h); | |
~Screenshot(); | |
inline int getX() { return x; } | |
inline int getY() { return y; } | |
inline int getWidth() { return width; } | |
inline int getHeight() { return height; } | |
cv::Mat getMat(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment