#include <windows.h>
#include <gdiplus.h>
//use cstring
#include <atlstr.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
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;
Gdiplus::GetImageEncodersSize(&num, &size);
if (size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if (pImageCodecInfo == NULL)
return -1; // Failure
Gdiplus::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
}
vo
VC++ 屏幕截图并保存为png格式
本文详细介绍了如何使用VC++编程语言,结合Windows API实现屏幕抓取功能,并将捕获的图像保存为PNG格式。通过示例代码,读者可以理解屏幕截图的原理以及文件保存的相关操作。
摘要由CSDN通过智能技术生成