Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, after a lot of effort here's the answer:</p> <pre><code>int SaveJpeg(HBITMAP hBmp, LPCWSTR lpszFilename, ULONG uQuality) { ULONG *pBitmap = NULL; CLSID imageCLSID; EncoderParameters encoderParams; int iRes = 0; typedef Status (WINAPI *pGdipCreateBitmapFromHBITMAP)(HBITMAP, HPALETTE, ULONG**); pGdipCreateBitmapFromHBITMAP lGdipCreateBitmapFromHBITMAP; typedef Status (WINAPI *pGdipSaveImageToFile)(ULONG *, const WCHAR*, const CLSID*, const EncoderParameters*); pGdipSaveImageToFile lGdipSaveImageToFile; // load GdipCreateBitmapFromHBITMAP lGdipCreateBitmapFromHBITMAP = (pGdipCreateBitmapFromHBITMAP)GetProcAddress(hModuleThread, "GdipCreateBitmapFromHBITMAP"); if(lGdipCreateBitmapFromHBITMAP == NULL) { // error return 0; } // load GdipSaveImageToFile lGdipSaveImageToFile = (pGdipSaveImageToFile)GetProcAddress(hModuleThread, "GdipSaveImageToFile"); if(lGdipSaveImageToFile == NULL) { // error return 0; } lGdipCreateBitmapFromHBITMAP(hBmp, NULL, &amp;pBitmap); iRes = GetEncoderClsid(L"image/jpeg", &amp;imageCLSID); if(iRes == -1) { // error return 0; } encoderParams.Count = 1; encoderParams.Parameter[0].NumberOfValues = 1; encoderParams.Parameter[0].Guid = EncoderQuality; encoderParams.Parameter[0].Type = EncoderParameterValueTypeLong; encoderParams.Parameter[0].Value = &amp;uQuality; lGdipSaveImageToFile(pBitmap, lpszFilename, &amp;imageCLSID, &amp;encoderParams); return 1; } </code></pre> <ul> <li><p>what is hModuleThread? Look in <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212%28v=vs.85%29.aspx" rel="noreferrer">here</a>. You can replace with <code>GetModuleHandle()</code></p></li> <li><p>what is GetEncoderClsid? Look <a href="http://msdn.microsoft.com/en-us/library/ms533843%28v=vs.85%29.aspx" rel="noreferrer">here</a>.</p></li> </ul> <p>Now the question is, how do I save the encoded pBitmap (as a jpeg) into a BYTE buffer?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload