2

I am trying to get a bitmap of what my dc draws, but when I convert it to Image I get

  File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 618, in ConvertToImage
    return _gdi_.Bitmap_ConvertToImage(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "bmp.Ok()" failed at ..\..\src\msw\dib.cpp(148) in wxDIB::Create(): wxDIB::Create(): invalid bitmap

It also gives the same error when trying to draw said bitmap to another dc. So I remember reading around here about a way to store the drawings of a ClientDC into a MemoryDC to then clean the ClientDC and draw the contents of the MemoryDC back onto it. What's the way to do that?

1 Answer 1

1
bitmap = wx.EmptyBitmap(width, height)

memory = wx.MemoryDC()
memory.SelectObject(bitmap)
#set pen, do drawing.
memory.SelectObject(wx.NullBitmap)

img = wx.ImageFromBitmap(bitmap)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.