我一直在编写一个我一直在写的程序的问题,并希望得到一些帮助或输入.对于某些背景,我使用Python 2.7和wxPython来做一个流媒体网络摄像头客户端.客户端从自己的线程中获取服务器中的图像,并将它们放入队列中.然后,GUI线程从队列中获取这些图像并将它们转换为wxBitmap对象.这种情况每0.5秒发生一次,效果很好.我能够将wxBitmap对象保存为文件,因此我知道一切正常.
我遇到的问题实际上是让wxBitmap对象显示在我的GUI上.我似乎唯一可以做GUI的工作是显示一个灰色矩形,其中应该是网络摄像头图像.
onPaint()当我想要刷新屏幕时,这是我的调用:
def onPaint(self,e):
## this is the function that actually draws and redraws the window
## to be displayed. I think it is something similar to blit()
## in other graphical display frameworks
print "in onPaint"
## create the device context object (graphics painter)
dc = wx.PaintDC(self)
dc.BeginDrawing()
## draw the bitmap to the screen
dc.DrawBitmap(self.imageBit,0,0,True)
dc.EndDrawing()
## test code.
## the following works and updates, which means that
## everything is being converted properly and updated.
## not sure why the dc won't paint it to the window.
self.imageBit.SaveFile("bit.bmp", wx.BITMAP_TYPE_BMP)
Run Code Online (Sandbox Code Playgroud)
简单地说,我不知道为什么它不起作用.从我的研究中我发现,因为我在Windows机器上我需要BeginDrawing()和EndDrawing()功能,所以我添加了它们.仍然无法正常工作.没有抛出错误或异常.
其他可能有助于解决此问题的问题:
wxFrame对象.也许wxPaintDC需要在另一种类型的容器中运行?实际上,也许我的__init__功能是什么来解决这个问题.我正确地设置了吗?
class viewWindow(wx.Frame):
imgSizer = (480,360)
def __init__(self, *args, **kw):
## this is called when an instance of this class is created
super(viewWindow,self).__init__(*args,**kw)
## here is where the actual stuff inside the frame is set up.
self.pnl = wx.Panel(self)
## create a button that opens up a Connection Window
#test = wx.Button(self.pnl, label='Connection Settings')
## test.Bind(wx.EVT_BUTTON, self.openConnectionWindow)
## create the wxImage for the web cam pic
self.image = wx.EmptyImage(self.imgSizer[0],self.imgSizer[1])
## create the wxBitmap so that the wxImage can be displayed
self.imageBit = wx.BitmapFromImage(self.image)
## create a timer that will update the window based of frame rate
self.timex = wx.Timer(self, wx.ID_OK)
self.timex.Start(500)
self.Bind(wx.EVT_TIMER, self.redraw, self.timex)
## need to do the following in order to display images in wxPython:
self.Bind(wx.EVT_PAINT, self.onPaint)
self.SetSize(self.imgSizer)
self.SetTitle('View Window')
self.Show()
Run Code Online (Sandbox Code Playgroud)
无论如何,提前感谢您的帮助.
编辑:我通过删除该行意外地解决了这个问题self.pnl = wx.Panel(self).
显然它渲染得很好,但位图位于面板下方.也许?我不太确定.我是整个wxPython的新手.
| 归档时间: |
|
| 查看次数: |
1403 次 |
| 最近记录: |