Results 1 to 5 of 5

Thread: Loading a Bitmap and blitting it to a DC.

  1. #1
    denniswrenn
    Guest

    Question

    Hello,
    How do I load a bitmap, and blit it to a DC? I also want to display it on the screen.


    Thanks,
    Dennis

    PS: I will not be using any MFC. Just a plain Win32 App.

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Wow I get to help Dennis, this is a first

    Note: I am writing this all from memory.

    Code:
    HDC hDC;
    HBITMAP hBitmap;
    
    hDC = CreateCompatibleDC(NULL);
    hBitmap = (HBITMAP)SelectObject(hDC, LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP) );
    //You could also use LoadImage instead of LoadBitmap
    
    BitBlt(hDCOfDeviceToPaint, StartXofDevice, StartYofDevice, PaintToX, PaintToY, hDC, StartXofBitmap, StartYofBitmap, SRCCOPY);
    
    //if you use case WM_PAINT do
    //PAINTSTRUCT ps;
    //BeginPaint(hWndofDeviceToPaintTo, &ps);
    //BitBlt(ps.hdc, StartXofDevice, StartYofDevice, PaintToX, PaintToY, hDC, StartXofBitmap, StartYofBitmap, SRCCOPY);
    //EndPaint(hWndofDeviceToPaintTo, &ps);
    If you want the bitmap to have a transparent back ground see:
    http://forums.vb-world.net/showthrea...threadid=54501
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Sorry at looking at your post I did not read BitBlt it to a DC. My mistake.

    To do that just add:

    Code:
    HDC hDC2;
    BITMAP bm;
    
    //Size
    GetObject(hBitmap, sizeof(BITMAP), &bm);
    
    hDC2 = CreateCompatibleDC(NULL);
    BitBlt(hDC2, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
    I also forgot you have to delete the objects and DCs when you are done with them

    Code:
    DeleteDC(hDC);
    DeleteDC(hDC2);
    DeleteObject(hBitmap);
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    Guest
    Thanks

    Another question, how do I blit the bitmap to the screen?

  5. #5
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    You just need a device handle to BitBlt it to. You can use almost anything, but static devices are the best. I made a staitic device that filled my entire window.

    Code:
    hWnd_Static = CreateWidnowEx(WS_EX_NOPARENTNOTIFY, "Static", NULL, WS_CHILD | SS_REALSIZEIMAGE, 0, 0, WindowWidth, WindowHeight, hWnd, NULL, hInstance, NULL);
    Then if you wanted to have it be there all the time you just catch the WM_PAINT when you are catching you messages and use this:

    Code:
    PAINTSTRUCT ps;
    
    case WM_PAINT:
      //This is really important, the window itself has to be painted.  This had me messed up for days
      BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
    
      BeginPaint(hWnd_Static, &ps);
        BitBlt(ps.hdc, 0, 0, (WindowWidth-5), WindowHeight, hDC, 0, 0, SRCCOPY);
      EndPaint(hWnd_Static, &ps);
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


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