CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2013
    Posts
    10

    Is it plousable MemDC to BitMap?

    Hello, I am having a problem with a code I wrote.
    As an expansion to a program I need to draw an bitmap and return the bitmap (im making an DLL)

    I am new to this and never workt with bitmaps bevore. I dit mix 2 tutorials 1 for loading a bitmap from a file and saving it to a MemD and print it to the window ussing BitBlt

    the second tutorial was drawing to a DC.

    So wat I dit (not knowing how wrong I was) load a dummy 256x256 bitmap file,
    putting it in to a MemDC then I was drawing to the MemDC
    and I was testing the program ussing BitBlt and workt perfect.
    But then it wend wrong in the program that has to usse the bitmap.
    Becorse all the drawing was on the MemDC itself not on the bitmap, and the code is as long as an sheet of wallpaper, so rewriting it will take ages (not to vorget I dont know how to draw on bitaps)

    so is ther a way I can usse this

    HBITMAP Bitmap_To_Return = CreateBitmap(xxxxxxxx);
    and then save the MemDC to Bitmap_To_Return

    so I dont have to rewrite all the code


    Thanks,

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Is it plousable MemDC to BitMap?

    That's exactly what you do with a memory DC. You select the bitmap in the DC and then draw on the DC. This paints on the bitmap.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Oct 2013
    Posts
    10

    Re: Is it plousable MemDC to BitMap?

    Quote Originally Posted by D_Drmmr View Post
    That's exactly what you do with a memory DC. You select the bitmap in the DC and then draw on the DC. This paints on the bitmap.

    Here is a part of my code:
    Code:
    #define export extern "C" __declspec (dllexport)
    export HANDLE Generate_map(HDC hDC , const char* ini_name, const char* bin_name ,int _X , int _Y)
    { 
    	     BMAP = LoadImage ( NULL,(LPCWSTR)L"MapGen\\Preview.bmp", IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE );
    		      
    	   	
    	    // bitmaps can only be selected into memory dcs:
    		HDC dcmem = CreateCompatibleDC ( NULL );
            
           if ( NULL == SelectObject ( dcmem, BMAP ) )
    	{	// failed to load bitmap into device context
    		DeleteDC ( dcmem ); 
    		return false; 
    	}
    
    SetPixel(dcmem,5   ,5 , RGB(128,128,128)); // ther is a loth of drawing going on but its all setpixel
    
    	/*
            BITMAP bm;
    	GetObject ( BMAP, sizeof(bm), &bm );
    	
    	
        // and blit it to the visible dc
    	if ( BitBlt ( hDC, _X, _Y, bm.bmWidth, bm.bmHeight, dcmem,0, 0, SRCCOPY ) == 0 ){DeleteDC ( dcmem );return NULL; }	// failed the blit
    	 */
    	 
    
    
    	
    		return BMAP;
    }
    now when I use the DLL to export BMAP with the drawings on it
    but the only thing the test program draws is “MapGen\\Preview.bmp”

    but when I enable the code between /* */ then I get the correct bitmap display but the dll draws it to the program,

    the program I write it for needs the index of the bitmap as an
    HBITMAP, HANDLE, or an byte array

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured