[英]PIL drawing an image then displaying it in wxpython
我在python中使用PIL繪制了圖像。
import Image
import ImageDraw
createCM():
img = Image.new("RGB", (400,400), "white")
draw = ImageDraw.Draw(img)
coords = [(100,70), (220, 310), (200,200)]
dotSize = 2
for (x,y) in coords:
draw.rectangle([x,y,x+dotSize-1,y+dotSize-1], fill="black")
我現在想做的就是在我的wxpython面板上顯示此內容。
我像這樣開始
CMchart = createCM(self)
self.vbox = wxBoxSizer(wx.VERTICAL)
self.vbox.Add(CMchart, 1, wx.LEFT | wx.TOP | wx.GROW)
self.vbox.AddSpacer(25)
self.SetSizer(self.vbox)
self.vbox.Fit(self)
這什么也沒顯示。 只想知道我要去哪里錯了
謝謝
不知道createcM會做什么,真的很難知道如何為您提供幫助。 但是它的缺點是要繪制圖像,需要從wx.Image加載數據,然后將其轉換為wx.Bitmap,然后使用DeviceContext進行繪制。 通常,首先繪制一個wx.MemoryDC,完成所有圖形更新后,再使用wx.PaintDC或wx.ClientDC繪制它。 看一看
http://wiki.wxpython.org/WorkingWithImages#PIL_.28Python_Imaging_Library.29
這為您提供了一個如何從PIL加載圖像的好例子
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.