资源简介
windows下的抓屏组件包含了GDI,DDRAW和DXGI等多种技术的抓屏代码
代码片段和文件信息
#include “../stdafx.h“
#include “VideoDxCaptor.h“
#include
#pragma comment(lib “Dwmapi.lib“)
VideoDXCaptor::VideoDXCaptor(void)
{
m_lpDDraw = NULL;
m_lpDDSPrime = NULL;
m_lpDDSBack = NULL;
}
VideoDXCaptor::~VideoDXCaptor(void)
{
Deinit();
}
BOOL VideoDXCaptor::Init()
{
HMODULE hDll = LoadLibrary(“ddraw.dll“);
if (hDll == NULL)
{
(“无法载入ddraw.dll\n“);
return FALSE;
}
// 载入ddraw的导入函数
PFN_DirectDrawCreate DirectDrawCreateFunc = (PFN_DirectDrawCreate)GetProcAddress(hDll “DirectDrawCreate“);
if (DirectDrawCreateFunc == NULL)
{
(“无法找到访问点:DirectDrawCreate\n“);
return FALSE;
}
HRESULT hr = DirectDrawCreateFunc(NULL &m_lpDDraw NULL);
if (FAILED(hr))
{
(“DirectDrawCreate失败\n“);
return FALSE;
}
hr = m_lpDDraw->SetCooperativeLevel(NULL DDSCL_NORMAL);
if (FAILED(hr))
{
(“SetCooperativeLevel失败\n“);
return FALSE;
}
DDSURFACEDESC DDSdesc;
ZeroMemory(&DDSdesc sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_CAPS;
DDSdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = m_lpDDraw->CreateSurface(&DDSdesc &m_lpDDSPrime NULL);
if (FAILED(hr))
{
(“CreateSurface 主表面失败\n“);
return FALSE;
}
ZeroMemory(&DDSdesc sizeof(DDSdesc));
DDSdesc.dwSize = sizeof(DDSdesc);
DDSdesc.dwFlags = DDSD_ALL;
hr = m_lpDDSPrime->GetSurfaceDesc(&DDSdesc);
if (FAILED(hr))
{
(“GetSurfaceDesc失败\n“);
return FALSE;
}
// 备份描述信息
memcpy(&m_DDSdesc &DDSdesc sizeof(DDSdesc));
DDSdesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
DDSdesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
hr = m_lpDDraw->CreateSurface(&DDSdesc &m_lpDDSBack 0);
if (FAILED(hr))
{
(“CreateSurface 后备表面失败\n“);
return FALSE;
}
return TRUE;
}
VOID VideoDXCaptor::Deinit()
{
if (m_lpDDSBack)
{
m_lpDDSBack->Release();
m_lpDDSBack = NULL;
}
if (m_lpDDSPrime)
{
m_lpDDSPrime->Release();
m_lpDDSPrime = NULL;
}
if (m_lpDDraw)
{
m_lpDDraw->Release();
m_lpDDraw = NULL;
}
}
BOOL VideoDXCaptor::CaptureImage(RECT &rect void *pData INT &nLen)
{
if (m_lpDDSBack == NULL)
{
(“DDraw对象未初始化\n“);
return FALSE;
}
HRESULT hr = m_lpDDSBack->BltFast(rect.left rect.top m_lpDDSPrime &rect DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
if (FAILED(hr))
{
(“BltFast失败\n“);
return FALSE;
}
DDSURFACEDESC surfDesc;
ZeroMemory(&surfDesc sizeof(surfDesc));
surfDesc.dwSize = sizeof(surfDesc);
//hr = lpDDSPrime->Lock(&rect &surfdesc DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR NULL);
hr = m_lpDDSBack->Lock(&rect &surfDesc DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR NULL);
if (FAILED(hr))
{
(“Lock失败\n“);
return FALSE;
}
// 这里拷贝的是32位数据,我们只需要24位的RGB数据
//memcpy(pBuf (BYTE*)surfDesc.lpSurface surfDesc.dwWidth * surfDesc.dwHeight * surfDesc.ddpfPixelFormat.dwRGBBitCount / 8);
// 将抓上来的图像转成RGB数据(
相关资源
- windows 注册表批量搜索替换等 RegWork
- Windows 10_MTK VCOM USB Preloader Drivers.zip
- Windows XP exFAT磁盘系统驱动程序
- Windows Server 2016建立域控服务器(AD)
- Crack_Quartus_Prime_Standard_Pro_15.1_Windows版
- KB925336补丁
- zlib的windows端应用工具
- STDF和ATDF相互转换的工具 (windows)
- vcruntime140_1.zip
- cudnn5.1 for cuda8.0适合于64位Windows7系统
- cuda8.0适于Windows10_64位
- CiscoSecureACSforWindowsSeverV4.2.txt
- windows xp 安装配置 DNS
- curl.exe CURL for windows
- VM虚拟机镜像集合windowsxp windows 7wind
- Qt做的windows运行win+r窗口
- unity4.x-2017.2.0f03全版本破解windows版本
- Windows平台下的网络调试助手
- Windows XP 自带的放大镜程序
- 基于Labwindows/CVI的虚拟示波器
- Windows画图源代码
- Windows记事本源代码
- 百度云 win10 深度学习环境 cuda_9.0.17
- VNC Open Source Code for Windows (4.1.3)
- IBM SPSS 25 序列号Windows、macOS、Linux适用
- windows下的定时器
- QT串口编程库--qextserialport-1.2win-alpha
- PB+GDI截屏保存JPG图片
- CUDA工具包9.0.176 for windows 10
- Windows Common Controls ActiveX Control DLL
评论
共有 条评论