I want to export some graphics file (BMP) using MMF2 filters but this chapter in the CHM Help has not been writed... Is it possible to have a new version of this help file with it ? And/Or is it possible to help me about that ?
Printable View
I want to export some graphics file (BMP) using MMF2 filters but this chapter in the CHM Help has not been writed... Is it possible to have a new version of this help file with it ? And/Or is it possible to help me about that ?
Hmm... there is an Exporting Graphic Files section in the SDK help file. If it's not in your version, redownload the SDK.
There is no Export example though, here is one. Note: I didn't try to compile this code, hopefully it works - let me know if there are any error.
PS: if you want to force the filter ID (= file format) and/or don't want a file selector, remove the call to ChoosePicture and use one of the predefined filters ID's (FILTERID_BMP, FILTERID_PNG, FILTERID_JPEG).Code:
// Export a surface as image file
//
// Note: fileName is overwritten by this function, it should contain at least MAX_PATH characters)
//
void ExportBitmapFile(LPRH rhPtr, LPSURFACE psf, LPSTR fileName)
{
DWORD dwFilterID = 0;
CImageFilterMgr pMgr = rhPtr->rh4.rh4Mv->mvImgFilterMgr;
OPENFILENAME ofn;
char szFileName[_MAX_PATH];
char szFileTitle[_MAX_PATH];
memset((LPVOID)&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
szFileName[0] = 0;
szFileTitle[0] = 0;
ofn.hwndOwner = rhPtr->rhHMainWin;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = sizeof(szFileName);
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = (LPTSTR)szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_NOCHANGEDIR;
// setup initial file name
strcpy(szFileName, (LPCSTR)fileName);
// Open selector and choose picture filename and format
if ( ChoosePicture(&ofn, FALSE, pMgr, &dwFilterID, PICSEL_IMAGES) )
{
// Return filename
fileName = ofn.lpstrFile;
// Export image
if ( !ExportImage(pMgr, fileName, psf, dwFilterID) )
{
// Error
}
}
}
Thanks Yves, I'll redownload my SDK because this chapter is white. :)
Actually I have a HBITMAP, How can I convert it into LPSURFACE ?
Ah, HBITMAP... can't you use / get a DIB instead of a HBITMAP? It's much easier to work with DIBs (and then load a DIB into a surface with the LoadImage function). Otherwise you can convert a HBITMAP to a DIB via a memory DC, I can explain it to you if you need it.