当前位置: 首页> 教育> 培训 > 工商企业网查询_建设通是正规网站吗_互联广告精准营销_搜索网站大全排名

工商企业网查询_建设通是正规网站吗_互联广告精准营销_搜索网站大全排名

时间:2025/9/9 6:01:41来源:https://blog.csdn.net/danxuezx/article/details/143018581 浏览次数:2次
工商企业网查询_建设通是正规网站吗_互联广告精准营销_搜索网站大全排名
#include <windows.h>
#include <stdio.h>// BMP 文件头大小
const int BMP_FILE_HEADER_SIZE = 14;
const int BMP_INFO_HEADER_SIZE = 40;void CaptureScreenAndSaveAsBMP(const wchar_t* filename)
{// 获取屏幕尺寸int screenWidth = GetSystemMetrics(SM_CXSCREEN);int screenHeight = GetSystemMetrics(SM_CYSCREEN);// 创建一个设备描述表(DIB)位图来保存屏幕截图HDC hdcMemory = CreateCompatibleDC(NULL);HBITMAP hbmScreen = CreateCompatibleBitmap(GetDC(NULL), screenWidth, screenHeight);SelectObject(hdcMemory, hbmScreen);// 捕获屏幕内容HDC hdcScreen = GetDC(NULL);BitBlt(hdcMemory, 0, 0, screenWidth, screenHeight, hdcScreen, 0, 0, SRCCOPY);// 创建 BMP 文件HANDLE hFile = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);if (hFile == INVALID_HANDLE_VALUE) {printf("无法创建文件 %s\n", filename);return;}// 计算 BMP 文件大小DWORD dwFileSize = BMP_FILE_HEADER_SIZE + BMP_INFO_HEADER_SIZE + screenWidth * screenHeight * 4;// 填充 BMP 文件头BITMAPFILEHEADER bfh;bfh.bfType = 0x4D42; // 'BM' 字符bfh.bfSize = dwFileSize;bfh.bfReserved1 = 0;bfh.bfReserved2 = 0;bfh.bfOffBits = BMP_FILE_HEADER_SIZE + BMP_INFO_HEADER_SIZE;// 填充 BMP 信息头BITMAPINFOHEADER bih;ZeroMemory(&bih, sizeof(bih));bih.biSize = BMP_INFO_HEADER_SIZE;bih.biWidth = screenWidth;bih.biHeight = -screenHeight; // 为了正确显示图像,高度应该是负数bih.biPlanes = 1;bih.biBitCount = 32;bih.biCompression = BI_RGB;bih.biSizeImage = 0; // 由 biBitCount 确定bih.biXPelsPerMeter = 0;bih.biYPelsPerMeter = 0;bih.biClrUsed = 0;bih.biClrImportant = 0;// 从 HBITMAP 读取像素数据DWORD dwScanLine = screenWidth * 4;BYTE* pBuffer = new BYTE[dwScanLine * screenHeight];GetBitmapBits(hbmScreen, dwScanLine * screenHeight, pBuffer);// 写入 BMP 文件头和信息头DWORD dwWritten;WriteFile(hFile, &bfh, sizeof(bfh), &dwWritten, NULL);WriteFile(hFile, &bih, sizeof(bih), &dwWritten, NULL);// 写入像素数据(从上往下写入)  WriteFile(hFile, pBuffer, dwScanLine * screenHeight, &dwWritten, NULL);delete[] pBuffer;CloseHandle(hFile);// 清理资源DeleteObject(hbmScreen);DeleteDC(hdcMemory);ReleaseDC(NULL, hdcScreen);
}int main()
{// 设置输出文件名wchar_t filename[] = L"screen_capture.bmp";// 调用函数截图并保存为 BMPCaptureScreenAndSaveAsBMP(filename);return 0;
}

一段windows下截全屏保存成bmp的完整代码,vs里创建控制台工程,代码拷贝进去编译后运行exe程序即可看到在程序目录下保存的屏幕图片

关键字:工商企业网查询_建设通是正规网站吗_互联广告精准营销_搜索网站大全排名

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: