wxPython中,dc.GetAsBitmap返回无效的位图 [英] wxpython, dc.GetAsBitmap returns an invalid bitmap

查看:446
本文介绍了wxPython中,dc.GetAsBitmap返回无效的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的DC画什么位图,但是当我将其转换为图像,我得到

 文件C:\\ Python25 \\ lib目录\\站点包\\ WX-2.8-MSW-UNI code \\ WX \\ _gdi.py,线路618,在ConvertToImage
    返回_gdi_.Bitmap_ConvertToImage(* ARGS,** kwargs)
wx._core.PyAssertionError:C ++断言bmp.Ok()在失败.. \\ .. \\ SRC \\ MSW \\ dib.cpp(148)在wxDIB ::创建():wxDIB ::创建():无效的位图

它试图所述位图绘制到另一台DC时也给出了同样的错误。所以我记得读在这里约了一种将ClientDC图纸存储到MemoryDC来然后清洁ClientDC并绘制MemoryDC的内容返回到它。什么是做到这一点的方法是什么?


解决方案

  =位wx.EmptyBitmap(宽,高)内存= wx.MemoryDC()
memory.SelectObject(位图)
#设置笔,绘图做。
memory.SelectObject(wx.NullBitmap)IMG = wx.ImageFromBitmap(位图)

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?

解决方案

bitmap = wx.EmptyBitmap(width, height)

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

img = wx.ImageFromBitmap(bitmap)

这篇关于wxPython中,dc.GetAsBitmap返回无效的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆