Wxpython, dc.GetAsBitmap returns an invalid bitmap

I try to get a bitmap of what my dc paints, 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 the mentioned bitmap on another dc. Therefore, I remember reading here about the method of storing ClientDC drawings in MemoryDC, then to clear ClientDC and draw the contents of MemoryDC back to it. How to do it?

+2
source share
1 answer
 bitmap = wx.EmptyBitmap(width, height) memory = wx.MemoryDC() memory.SelectObject(bitmap) #set pen, do drawing. memory.SelectObject(wx.NullBitmap) img = wx.ImageFromBitmap(bitmap) 
+1
source

Source: https://habr.com/ru/post/1300236/


All Articles