1 static int GetEncoderClsid(string format, CLSID* clsidEncoder) 2 { 3 int f = 0; 4 uint uenc = 0u, usize = 0u; 5 ushort* psz = _L(format); 6 if (GdipGetImageEncodersSize(&uenc, &usize) == 0) 7 { 8 ImageCodecInfo* pici = (ImageCodecInfo*)LocalAlloc(0u, (void*)usize); 9 if (GdipGetImageEncoders(uenc, usize, pici) == 0) 10 { 11 for (int i = 0; i < uenc; i++) 12 { 13 if (lstrcmpW(pici->MimeType, psz) == 0) 14 { 15 *clsidEncoder = pici->Clsid; 16 f = 1; 17 break; 18 } 19 pici++; 20 } 21 } 22 GlobalFree(pici); 23 } 24 _Lr(psz); 25 return f; 26 }
1 static int GetImageLength(GpImage* image, string format, void** usize) 2 { 3 CLSID clsid; 4 if (GetEncoderClsid(format, &clsid) != 0) 5 { 6 void* hgbl = GlobalAlloc(GMEM_MOVEABLE, null); 7 if (hgbl != null) 8 { 9 void* pstm; 10 if (SUCCEEDED(CreateStreamOnHGlobal(hgbl, 1, &pstm))) 11 { 12 if (GdipSaveImageToStream(image, pstm, &clsid, null) == 0) 13 { 14 *usize = GlobalSize(hgbl); 15 return 1; 16 } 17 Marshal.Release((IntPtr)pstm); 18 } 19 GlobalFree(hgbl); 20 } 21 } 22 return 0; 23 }
C# [GDI+] [API] Get Image bytes Length
原文:https://www.cnblogs.com/shitekudasai/p/10586214.html