我正在尝试获取我的DC绘制的位图,但是当我将其转换为Image时,我得到了
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
当尝试将所述位图绘制到另一个dc时,它也会出现相同的错误。所以我记得在这里阅读有关将ClientDC的图形存储到MemoryDC中然后清理ClientDC并将MemoryDC的内容重新绘制到它上面的方法。有什么办法呢?
答案 0 :(得分:1)
bitmap = wx.EmptyBitmap(width, height)
memory = wx.MemoryDC()
memory.SelectObject(bitmap)
#set pen, do drawing.
memory.SelectObject(wx.NullBitmap)
img = wx.ImageFromBitmap(bitmap)