GDI+ GetEncoderClsid

// 导入GDI库

#include <gdiplus.h>
using namespace Gdiplus;
#pragma  comment(lib, "gdiplus.lib")


ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput StartupInput;

GdiplusStartup(&m_gdiplusToken,&StartupInput,NULL); // GDI+初始化
Gdiplus::GdiplusShutdown(m_gdiplusToken); // GDI+卸载


/**
@name    GetEncoderClsid
@brief   取图片类型GLSID
@param[in]        const WCHAR * format
@param[in]        CLSID * pClsid
@return           int
*/
int CTest::GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
    UINT  num = 0;
    UINT  size = 0;
    ImageCodecInfo* pImageCodecInfo = NULL;
    GetImageEncodersSize(&num, &size);
    if(size == 0)
        return -1;

    pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
    if(pImageCodecInfo == NULL)
        return -1;

    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;
        }    
    }
    free(pImageCodecInfo);
    return -1;
}

用法:

CLSID encoderClsid
GetEncoderClsid(L"image/jpeg", &m_jpgClsid);
GetEncoderClsid(L"image/png", &encoderClsid); 
GetEncoderClsid(L"image/bmp", &encoderClsid);
GetEncoderClsid(L"image/gif", &encoderClsid);
GetEncoderClsid(L"image/tiff", &encoderClsid);








你可能感兴趣的:(绘图,jpg,CLSID,GDI+,gdi)