Home > Software engineering >  How to use BitBlt in Python
How to use BitBlt in Python

Time:01-31

How would I go about using BitBlt in python? I know how to use PatBlt, but I was wondering how you use BitBlt. How would I put a image on the GDI?

CodePudding user response:

If you already know how to use PatBlt then you are most of the way there.

BitBlt just transfers pixels from one DC to another. Often one DC has a bitmap selected into it and the other DC is the screen. It can be used to take screen shots, display pictures or do double buffering.

Let's say you have a bitmap loaded from LoadImage and you want to display it in WM_PAINT.

  1. Call BeginPaint to get a DC for your window (the destination).
  2. Call CreateCompatibleDC to create a source DC that is compatible with the destination.
  3. Call SelectObject to select the bitmap (HBITMAP) into the source DC. You should store the return value so it can be restored during cleanup.
  4. Call BitBlt(destination DC, ..., source DC, ...., SRCCOPY) to copy the bitmap pixels to the window.
  5. Call SelectObject to restore the original value.
  6. Call DeleteDC to destroy the source DC.
  7. Call EndPaint.
  •  Tags:  
  • Related