目的:有一个项目需求是,隔几秒对电脑屏幕截屏一次,找了一会儿,发现windows自带的GDI库就可以,然后试了一下,发现效果不错,内存占用很低,单次触发8ms。
这段代码还需要一个txt文件一起运行,详见注释
#include <atlimage.h>
#include <atltime.h>
#include <conio.h>
#include <iostream>
#include <Windows.h>
#include <fstream>
#include <cassert>
#include <string>
using namespace std;
//截取全屏保存为png
void ScreenShot(int fWidthScreen,int fHeightScreen,int nWidthScreen,int nHeightScreen,int Time_deley)
{
HDC hDCScreen = ::GetDC(NULL);