注意:如果没有启动GDI +, 在lockbits 时会返回失败!
1.在stdafx.h 中加入
#define ULONG_PTR unsigned long
#include <Gdiplus.h>
using namespace Gdiplus;
2.在头文件中定义变量:
ULONG_PTR m_gdiplusToken;
3.在类初始化或启动时:
GdiplusStartupInput m_gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);//启动gdi+
4.在析构或停止函数中
Gdiplus::GdiplusShutdown(m_gdiplusToken); //停止GDI+
5.增加函数:
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)