相关疑难解决方法(0)

在Windows中使用C++截取窗口截图的最佳方法是什么?

在Windows下使用C++截取正在运行的应用程序的屏幕截图的最佳(最简单)方法是什么?

c++ windows screenshot

36
推荐指数
1
解决办法
3万
查看次数

如何截取屏幕截图并将其保存为Windows上的JPEG?

我试图找到一种(有点)简单的方法来在窗口上截取屏幕截图并将生成的HBITMAP保存为JPEG.这里棘手的部分是,因为代码在CI中不能使用GDI +,并且由于代码是更大程序的模块,我不能使用外部库(如libjpeg).

此代码截取屏幕截图并返回HBITMAP.将该位图保存到文件中很容易.问题是位图是2或3mb.

HDC hDCMem = CreateCompatibleDC(NULL);
HBITMAP hBmp;
RECT rect;
HDC hDC;
HGDIOBJ hOld;    

GetWindowRect(hWnd, & rect);

hBmp = NULL;

{
    hDC = GetDC(hWnd);
    hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
    ReleaseDC(hWnd, hDC);
}

hOld = SelectObject(hDCMem, hBmp);
SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);

SelectObject(hDCMem, hOld);
DeleteObject(hDCMem);

return hBmp;
Run Code Online (Sandbox Code Playgroud)

关于如何做到这一点的任何想法?非常感谢,任何帮助表示赞赏

编辑:因为我们走向GDI +的方向我想我会发布代码iv C++,可以截取屏幕截图并使用GDI +将其转换为JPEG.如果有人知道如何使用FLAT GDI +实现这一目标我会很感激帮助.码:

    #include <windows.h>
#include <stdio.h>
#include <gdiplus.h>

using namespace Gdiplus;


int GetEncoderClsid(WCHAR *format, CLSID *pClsid) …
Run Code Online (Sandbox Code Playgroud)

c windows jpeg gdi+ screenshot

13
推荐指数
2
解决办法
3万
查看次数

截取屏幕截图

即时尝试使用此代码:

bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);

bool ScreenCapture(int x, int y, int width, int height, char *filename){
// get a DC compat. w/ the screen
HDC hDc = CreateCompatibleDC(0);

// make a bmp in memory to store the capture in
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);

// join em up
SelectObject(hDc, hBmp);

// copy from the screen to my bitmap
BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);

// save my bitmap
bool …
Run Code Online (Sandbox Code Playgroud)

c screenshot image screen

3
推荐指数
1
解决办法
365
查看次数

标签 统计

screenshot ×3

c ×2

windows ×2

c++ ×1

gdi+ ×1

image ×1

jpeg ×1

screen ×1