1: /* format 取值为:
2: image/bmp
3: image/jpeg
4: image/gif
5: image/tiff
6: image/png
7: */
8: int GetEncoderClsid( const WCHAR* format, CLSID* pClsid )
9: {
10: UINT num = 0; // number of image encoders
11: UINT size = 0; // size of the image encoder array in bytes
12:
13: ImageCodecInfo* pImageCodecInfo = NULL;
14:
15: GetImageEncodersSize(&num, &size);
16: if(size == 0)
17: return -1; // Failure
18:
19: pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
20: if(pImageCodecInfo == NULL)
21: return -1; // Failure
22:
23: GetImageEncoders(num, size, pImageCodecInfo);
24:
25: for(UINT j = 0; j < num; ++j)
26: {
27: if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
28: {
29: *pClsid = pImageCodecInfo[j].Clsid;
30: free(pImageCodecInfo);
31: return j; // Success
32: }
33: }
34:
35: free(pImageCodecInfo);
36: return -1; // Failure
37:
38: }