Previously wrote an article "VC + + using CImage in memory JPEG conversion BMP picture", through the CImage realized in memory JPEG to BMP.
Since JPEG can be transferred to BMP, that CImage also supports BMP-to-JPEG, in contrast to the previous article, which relies on the CImage load function, BMP-to-JPEG is implemented by the Save function:
The use of the IStream interface is also a function overload, specifically refer to msdn:http://msdn.microsoft.com/zh-cn/library/d06f3fhw.aspx
The following is a code that uses CImage to convert JPEG in-memory BMP:
unsigned long bmp2jpeg (char* punzipdata,unsigned long ulunzipdatalen,char** pbuffer) {unsigned long ulbufferlen = 0; Hglobal hglobal = GlobalAlloc (gmem_moveable, Ulunzipdatalen); void* pData = GlobalLock (hglobal); memcpy (PData, Punzipdata, Ulunzipdatalen); GlobalUnlock (hglobal); istream* pStream = NULL; if (CreateStreamOnHGlobal (Hglobal, TRUE, & pStream) = = S_OK) {CImage image; if (SUCCEEDED (image). Load (PStream))) {istream* poutstream = NULL; if (CreateStreamOnHGlobal (NULL, TRUE, & poutstream) = = S_OK) {image. Save (Poutstream, gdiplus::imageformatjpeg); Hglobal houtglobal= NULL; Gethglobalfromstream (Poutstream,&houtglobal); Lpbyte pbits= (LPBYTE) GlobalLock (houtglobal); Ulbufferlen = (DWORD) globalsize (pbits); *pbuffer = new Char[ulbufferlen]; memcpy (*pbuffer, pbits, Ulbufferlen); GlobalUnlock (Houtglobal);p outstream->release ();}} Pstream->release (); } GlobalFree (hglobal); return Ulbufferlen;}
Record, for the better of myself!
VC + + uses CImage to convert JPEG images in memory bmp