2008年6月1日日曜日

alphaのあるimageを重ねて描画する。

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク

wx.Image::Pasteをしても駄目。

wxEmptybitmap, blit and transparency

MemoryDCにDrawしてしまうのが簡単。

追記:
- EmptyBitmap全体に描画しないと画像にゴミが残る・・・。
- MemoryDCといえどもPaintDCと同時に存在できない(Windows)。


import wx

class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
bitmap = wx.EmptyBitmap(400, 400)
dc = wx.MemoryDC()
dc.SelectObject(bitmap)
other = wx.Image('other.jpg', wx.BITMAP_TYPE_JPEG)
dc.DrawBitmap(other.ConvertToBitmap(), 0, 0)

chip = wx.Image('chip.png', wx.BITMAP_TYPE_PNG)
dc.DrawBitmap(chip.ConvertToBitmap(), 0, 0)
self.bitmap = bitmap
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Show()

def OnPaint(self, evt):
dc = wx.BufferedPaintDC(self)
dc.SetBackground(wx.Brush('sky blue'))
dc.Clear()
dc.DrawBitmap(self.bitmap, 0, 0)


app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

0 件のコメント: