use of com.sun.jna.platform.win32.GDI32 in project HearthStats.net-Uploader by HearthStats.
the class ProgramHelperWindows method _getScreenCaptureWindows.
private BufferedImage _getScreenCaptureWindows(HWND hWnd) {
HDC hdcWindow = User32.INSTANCE.GetDC(hWnd);
HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow);
RECT bounds = new RECT();
User32Extra.INSTANCE.GetClientRect(hWnd, bounds);
// check to make sure the window's not minimized
if (bounds.toRectangle().width >= 1024) {
if (isMinimised) {
_notifyObserversOfChangeTo("Hearthstone window restored");
isMinimised = false;
}
if (isFullScreen(bounds.toRectangle())) {
if (!isFullscreenFlag) {
_notifyObserversOfChangeTo("Hearthstone running in fullscreen");
isFullscreenFlag = true;
}
return null;
} else {
int width = bounds.right - bounds.left;
int height = bounds.bottom - bounds.top;
HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height);
HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap);
GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY);
GDI32.INSTANCE.SelectObject(hdcMemDC, hOld);
GDI32.INSTANCE.DeleteDC(hdcMemDC);
BITMAPINFO bmi = new BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
Memory buffer = new Memory(width * height * 4);
GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, buffer.getIntArray(0, width * height), 0, width);
GDI32.INSTANCE.DeleteObject(hBitmap);
User32.INSTANCE.ReleaseDC(hWnd, hdcWindow);
return image;
}
}
if (!isMinimised) {
// that the window has been minimised.
if (minimisedCount < ITERATIONS_FOR_MINIMISE) {
minimisedCount++;
} else {
_notifyObserversOfChangeTo("Warning! Hearthstone minimized. No detection possible.");
isMinimised = true;
minimisedCount = 0;
}
}
return null;
}
Aggregations