发现压缩JPEG到文件性能比较差,就想了一个办法直接压缩DIB到内存流IStream。因为用的是CDIBSection,所以直接在里面加了一个函数,代码不多:
HRESULT CDIBSection::SaveAsJpeg(LPCTSTR pszFileName, IStream* pStream)
{
IImagingFactory *pImgFactory = NULL;
HRESULT hr = S_OK;
//测试发现只能压缩32BIT图。
PBITMAPINFOHEADER pbi = GetBitmapInfoHeader();
if(pbi->biBitCount != 32)
return E_INVALIDARG;
// Create the imaging factory.
if (SUCCEEDED( hr = CoCreateInstance (CLSID_ImagingFactory
, NULL, CLSCTX_INPROC_SERVER
, IID_IImagingFactory, (void **)&pImgFactory)))
{
//找到JPEG的编码器
UINT uCount = 0;
ImageCodecInfo* imageCodecInfo=NULL;
GUID encodeClassId={0};
pImgFactory->GetInstalledEncoders(&uCount, &imageCodecInfo);
const TCHAR *m_szJPGMimeType = L"image/jpeg";
for(UINT i = 0; i <