VC + + uses CImage to convert JPEG images in memory bmp

Source: Internet
Author: User

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:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.