Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Create a bitmap file

Create a bitmap file

Scheduled Pinned Locked Moved C / C++ / MFC
comgraphicsdata-structuresperformancelearning
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Francis B
    wrote on last edited by
    #1

    I'm trying to create a bitmap file from a memory device context but the only thing I create is a complete white bitmap. X| Here my code:

    MyFunction()
    {
    CClientDC dc(this); //dc of dialog
    CRect rectBF(0,0,450,450);
    CBitmap bmp, *poldbmp;
    CDC memdc;

         // Load the bitmap resource
         bmp.CreateCompatibleBitmap(&dc, 450, 450);
    
         // Create a compatible memory DC
         memdc.CreateCompatibleDC( &dc );
    
    		 
         // Select the bitmap into the DC
         poldbmp = memdc.SelectObject( &bmp );
         //CGraphWnd was created by Paul Barvinko - [A 2D data visualisation class](http://www.codeproject.com/miscctrl/graph2d.asp)
    m\_ctlGraphWnd.DrawGraphToDC(&memdc, rectBF); //Copy graph to DC
    
         memdc.SelectObject(poldbmp);
    
    CPalette palette;
    
         //Initialize palette
    if( dc.GetDeviceCaps(RASTERCAPS) & RC\_PALETTE )
    {
    	UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) \* 256);
    	LOGPALETTE \*pLP = (LOGPALETTE \*) new BYTE\[nSize\];
    	pLP->palVersion = 0x300;
    
    	pLP->palNumEntries = 
    			GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry );
    
    	// Create the palette
    	palette.CreatePalette( pLP );
    
    	delete\[\] pLP;
    }
    

    This code above works correctly. The graph was drawn in memdc.

         //Function was created by Zafir Anjum - [Converting DDB to DIB](http://www.codeguru.com/bitmap/ddb_to_dib.shtml)
    HANDLE hDIB = DDBToDIB(bmp, BI\_RGB, &palette);
    
    if( hDIB == NULL )
    	return ;
    
         //Function was created by Zafir Anjum - [Writing a bitmap to a BMP file](http://www.codeguru.com/bitmap/bitmap_to_file.shtml)
    WriteDIB(\_T("graph.bmp"), hDIB);
    
    GlobalFree( hDIB );
    

    }

    I don't know why but operations done on memdc aren't reflected in CBitmap bmp. Thanks in advance!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups