I have actually a HBITMAP and I would like to know how can I save it as a picture file thanks to MMF2 filters.
Thanks for the help.![]()







I have actually a HBITMAP and I would like to know how can I save it as a picture file thanks to MMF2 filters.
Thanks for the help.![]()
HBITMAP to a cSurface? This should work:
Not investigated MMF's filters though, so can't help with that...Code:// HBITMAP hBitmap; (this is your bitmap) cSurface srf; HDC hDC = srf.GetDC (); BITMAPINFO bmpInfo; LPBYTE pBuf; GetDIBits (hDC, hBitmap, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS); if (bmpInfo.bmiHeader.biSizeImage <= 0) bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth * abs(bmpInfo.bmiHeader.biHeight) * (bmpInfo.bmiHeader.biBitCount + 7) / 8; pBuf = new BYTE[bmpInfo.bmiHeader.biSizeImage]; bmpInfo.bmiHeader.biCompression = BI_RGB; GetDIBits (hDC, hBitmap, 0, bmpInfo.bmiHeader.biHeight, pBuf, &bmpInfo, DIB_RGB_COLORS); srf.ReleaseDC (); srf.LoadImage (&bmpInfo, pBuf); delete [] pBuf; // srf contains the image in the HBITMAP

This won't work if the HBITMAP is in 256 colors, you have to dynamically allocate bmpInfo : sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD).







Thanks a lot.
How can I know if the HBitmap is in 256 ?
Maybe you have an example to manage fullcolors and indexed pictures ?
Thanks a lot for your help.![]()

No need to know it, just allocate the memory and let the GetDIBits and LoadImage functions to handle it.![]()







Yeah. THanks, I'll try it today.![]()







I get several errors, when I try to use filters... When I include "ImgFlt.h" in "Common.h" :
How do you dynamically allocate memory for "bmpInfos" ? I try:Code:..\..\Inc\ImgFlt.h(14) : error C2061: syntax error : identifier 'CImageFilter' ..\..\Inc\ImgFlt.h(15) : error C2061: syntax error : identifier 'CImageFilter' ..\..\Inc\ImgFlt.h(16) : error C2061: syntax error : identifier 'CImageFilter' ..\..\Inc\ImgFlt.h(17) : error C2061: syntax error : identifier 'CImageFilter' ..\..\Inc\ImgFlt.h(18) : error C2061: syntax error : identifier 'CImageFilter' ..\..\Inc\ImgFlt.h(19) : error C2061: syntax error : identifier 'CImageFilter'
But it says :Code:BITMAPINFO bmpInfo = (BITMAPINFO*)malloc(sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD));
Thanks...Code:error C2440: 'initializing' : cannot convert from 'struct tagBITMAPINFO *' to 'struct tagBITMAPINFO'![]()







Ok, I've corrected the bug to allocate (I'm too bad sometimes) :
But now, a BMP image is created but it's not a valide one. Is the code above is correct (without using MMF2 filters) ? Maybe the bug is in my HBitmap now...Code://MMF2 Surface cSurface srf; //File name LPSTR filePath = (LPSTR)param1; //Conversion HBitmap en DIB HDC hDC = srf.GetDC(); LPBITMAPINFO bmpInfo = (LPBITMAPINFO)malloc(sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)); LPBYTE pBuf; //memset((void*)&bmpInfo,0,sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)); GetDIBits(hDC, rdPtr->hIcon, 0, 0, NULL, bmpInfo, DIB_RGB_COLORS); if(bmpInfo->bmiHeader.biSizeImage <= 0) bmpInfo->bmiHeader.biSizeImage = bmpInfo->bmiHeader.biWidth * abs(bmpInfo->bmiHeader.biHeight) * (bmpInfo->bmiHeader.biBitCount + 7) / 8; pBuf = new BYTE[bmpInfo->bmiHeader.biSizeImage]; bmpInfo->bmiHeader.biCompression = BI_RGB; //Conversion DIB en MMF2 Surface GetDIBits(hDC, rdPtr->hIcon, 0, bmpInfo->bmiHeader.biHeight, pBuf, bmpInfo, DIB_RGB_COLORS); //Libération mémoire srf.ReleaseDC(hDC); srf.LoadImage(bmpInfo, pBuf); delete [] pBuf; // srf contains the image in the HBITMAP srf.SaveImage(filePath,SI_NONE); /* //Filter DWORD dwFilterID = FILTERID_BMP;//FILTERID_PNG, FILTERID_JPEG //Filter Manager LPRH rhPtr = rdPtr->rHo.hoAdRunHeader; CImageFilterMgr pMgr = rhPtr->rh4.rh4Mv->mvImgFilterMgr; ExportImage(pMgr, filePath, &srf, dwFilterID); */
After you allocate bmpInfo...
You need to include ImageFlt.h before ImgFlt.h, as that contains the class definitions.Code:bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);







Thanks, ChrisB.
Now if I include ImageFlt.h and ImgFlt.h, no errors occurs on compilation...
...but when I save the image (ex hbitmap) a BMP file is created and can't be read (58 bytes, 0x0 bitmap file) like before...
If I uncomment the Export, I obtain this error :
Thanks again for helpCode:error C2065: 'FILTERID_BMP' : undeclared identifier![]()