User Tag List

Results 1 to 10 of 10

Thread: [SDK] How to save a HBITMAP with MMF2 filters ?

  1. #1
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    Sphax's Avatar
    Join Date
    Jun 2006
    Location
    Paris, France
    Posts
    4,454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [SDK] How to save a HBITMAP with MMF2 filters ?

    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.

  2. #2
    Firecodemonkey

    Join Date
    Aug 2006
    Location
    London, UK
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    HBITMAP to a cSurface? This should work:

    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
    Not investigated MMF's filters though, so can't help with that...

  3. #3
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    14,022
    Mentioned
    279 Post(s)
    Tagged
    3 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

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

  4. #4
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    Sphax's Avatar
    Join Date
    Jun 2006
    Location
    Paris, France
    Posts
    4,454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    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.

  5. #5
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    14,022
    Mentioned
    279 Post(s)
    Tagged
    3 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    No need to know it, just allocate the memory and let the GetDIBits and LoadImage functions to handle it.

  6. #6
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    Sphax's Avatar
    Join Date
    Jun 2006
    Location
    Paris, France
    Posts
    4,454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    Yeah. THanks, I'll try it today.

  7. #7
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    Sphax's Avatar
    Join Date
    Jun 2006
    Location
    Paris, France
    Posts
    4,454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    I get several errors, when I try to use filters... When I include "ImgFlt.h" in "Common.h" :
    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'
    How do you dynamically allocate memory for "bmpInfos" ? I try:
    Code:
    BITMAPINFO bmpInfo = (BITMAPINFO*)malloc(sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD));
    But it says :
    Code:
    error C2440: 'initializing' : cannot convert from 'struct tagBITMAPINFO *' to 'struct tagBITMAPINFO'
    Thanks...

  8. #8
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    Sphax's Avatar
    Join Date
    Jun 2006
    Location
    Paris, France
    Posts
    4,454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    Ok, I've corrected the bug to allocate (I'm too bad sometimes ) :
    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);
    */
    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...

  9. #9
    Firecodemonkey

    Join Date
    Aug 2006
    Location
    London, UK
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    After you allocate bmpInfo...
    Code:
    bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    You need to include ImageFlt.h before ImgFlt.h, as that contains the class definitions.

  10. #10
    Forum Moderator Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    Sphax's Avatar
    Join Date
    Jun 2006
    Location
    Paris, France
    Posts
    4,454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: [SDK] How to save a HBITMAP with MMF2 filters

    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 :
    Code:
    error C2065: 'FILTERID_BMP' : undeclared identifier
    Thanks again for help

Similar Threads

  1. How to set up File object filters?
    By RGBreality in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 3rd March 2011, 01:18 PM
  2. More Image Filters?
    By Dines in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 29th April 2009, 03:10 PM
  3. converting cSurface to HBITMAP
    By Looki in forum Extension Developers Lobby
    Replies: 3
    Last Post: 8th November 2008, 08:56 PM
  4. Image Filters
    By dingdong in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 14th September 2007, 08:39 PM
  5. Filters?
    By Cocodrilo in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 4th July 2006, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •