Win32 Grab Screen
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
#include <iostream> #include <windows.h> #include <gdiplus.h> #include <memory> using namespace Gdiplus; using namespace std; int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) { return -1; // Failure } pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if(pImageCodecInfo == NULL) { return -1; // Failure } GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure } void BitmapToJpg(HBITMAP hbmpImage, int width, int height) { Bitmap *p_bmp = Bitmap::FromHBITMAP(hbmpImage, NULL); //Bitmap *p_bmp = new Bitmap(width, height, PixelFormat32bppARGB); CLSID pngClsid; int result = GetEncoderClsid(L"image/jpeg", &pngClsid); if(result != -1) std::cout << "Encoder succeeded" << std::endl; else std::cout << "Encoder failed" << std::endl; p_bmp->Save(L"screen.jpg", &pngClsid, NULL); delete p_bmp; } bool ScreenCapture(int x, int y, int width, int height, char *filename) { HDC hDc = CreateCompatibleDC(0); HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height); SelectObject(hDc, hBmp); BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY); BitmapToJpg(hBmp, width, height); DeleteObject(hBmp); return true; } int main() { // Initialize GDI+. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); int x1 = 0; int y1 = 0; int x2 = GetSystemMetrics(SM_CXSCREEN); int y2 = GetSystemMetrics(SM_CYSCREEN); ScreenCapture(x1, y1, x2 - x1, y2 - y1, "screen.jpg"); //Shutdown GDI+ GdiplusShutdown(gdiplusToken); return 0; } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=414