CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    9

    Am I BitBlt'ing Bitmap correctly? wrong code?

    Im trying to replace my gdi+ DrawImage() code to BitBlt'ing code to speed things up but my image won't paint to the screen?

    Is this the correct code? thanks.

    hdc = BeginPaint (hWnd, &ps);
    HDC hdcMem = CreateCompatibleDC(hdc);
    SelectObject(hdcMem, myBitmap);
    BitBlt(hdc, 0, 0, myBitmap->GetWidth(), myBitmap->GetHeight(), hdcMem, 0, 0, SRCCOPY);
    DeleteDC(hdcMem);


    When I was using DrawImage() everything was fine. but too slow.
    Im really am sure this is not the right code.

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Am I BitBlt'ing Bitmap correctly? wrong code?

    Where is "MyBitmap" defined/initialized?

  3. #3
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: Am I BitBlt'ing Bitmap correctly? wrong code?

    Did the OP call EndPaint()?

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Am I BitBlt'ing Bitmap correctly? wrong code?

    In SelectObject, you have to pass a HBITMAP handle and not a pointer to Gdiplus::Bitmap object.
    Code:
       //...
       HDC hdcMem = ::CreateCompatibleDC(hdc);
       HBITMAP hBitmap = NULL;
       Color color;
       myBitmap->GetHBITMAP(color, &hBitmap);
       HBITMAP hBitmapOld = (HBITMAP)::SelectObject(hdcMem, hBitmap);
       ::BitBlt(hdc, 0, 0, myBitmap->GetWidth(), myBitmap->GetHeight(), hdcMem, 0, 0, SRCCOPY);
       ::SelectObject(hdcMem, hBitmapOld);
       ::DeleteDC(hdcMem);
       // ...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.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

Featured