ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

windows 窗口采集和桌面采集的解决方案

windows 窗口采集和桌面采集的解决方案 前言最近在研究windows截屏的功能。窗口截图(HWND)PrintWindow 参考代码QT的grabWindow 参考代码winapi.BitBlt 参考代码以上方法都无法抓取以下类的app图片(来自obs代码chromeMozillaXLMAIN /*excel */PPTFrameClass /* powerpoint* /OpusApp /* word */ApplicationFrameWindowwindows.UI.Core.CoreWindow而只能采用“桌面截图”的方式桌面截图pyautogui.screenshotImageGrab.grab网上查找资料windows 窗口采集里面有详细的桌面截图介绍。最终采用的方式如果操作系统 win10 1903 版本就使用wgc 方式否则采用BitBlt对于BitBlt 也无法截图的窗口则采用桌面截屏。WGC使用方法Windows Graphics Capture(wgc)窗口采集的dll库 封装了使用dll库。需要设置抓图的窗口即可回调数据。struct ST_IMAGE { int width; //图片宽 int height; //图片高 int bits; //单像素bits数这里固定图像格式为 B8G8R8A8(bgra 32bits) int rowPitch; //每行像素的bytes数 width*bits/8 int slicePitch; //整幅图像的bytes数 rowPitch*height unsigned char* pixels; //Pointer to the system memory buffer for the pixel data }; /** * brief 图像回调。 * * 注意: stImage.pixels 的内存数据只读不可修改。如要特殊处理请copy */ typedef void (STDCALL *image_CallBack_PF)(ST_IMAGE stImage,void* pUser); /* * brief 初始化必须不可重复调用 win_hwndNULL 内部创建显示窗口!NULL 使用外部窗口 * auth 授权码未授权受限0.25帧/s授权后可达60帧/s。 获取授权码可email: 86122114qq.com */ EXPORT_API int STDCALL wgclib_init(void* win_hwnd,char* auth); /* * brief 设置抓拍的窗口句柄 */ EXPORT_API void STDCALL wgclib_capture_hwnd(void* hwnd,image_CallBack_PF pFunc,void *pUser);如何保存灰度图片在代码SimpleCapture.cpp 中增加成员函数staticuint8_t*s_pixnullptr;staticints_slicePitch0;voidTakeSnapshot(ST_IMAGE stImage,void*pUser){ST_IMAGE copy_im{0};// 图片格式BGRA8变灰度图{intpixstImage.bits;copy_im.rowPitchstImage.width*pix;copy_im.slicePitchstImage.rowPitch*stImage.height;if(s_slicePitch!copy_im.slicePitch){if(s_pix){delete[]s_pix;s_pixnullptr;}s_pixnewuint8_t[copy_im.slicePitch];s_slicePitchcopy_im.slicePitch;}copy_im.pixelss_pix;for(inti0,j0;icopy_im.slicePitch;i){uint8_tbstImage.pixels[j];uint8_tgstImage.pixels[j1];uint8_trstImage.pixels[j2];copy_im.pixels[i]b;jj4;}staticintfile_index0;wchar_tbuff[260]{0};swprintf(buff,260,Loutput_%d.jpg,file_index);//save2jpg(copy_im );file_index;}}## PrintWindow 和 BitBlt[https://worktile.com/kb/p/6009](https://worktile.com/kb/p/6009)
返回列表