ich versuche derzeit zwei png dateien übereinander zu legen und mir ein einzelnes Bitmap object zurückgeben zu lassen.
Allerdings verliert das untere Bild seine transparent und erhält einen schwarzen Hintergrund. Mache ich irgendwas verkehrt ? =(
Hier sollte mir das gemergede Image zurückgegeben.
Code: Alles auswählen
def mergeBitmaps(self, bmp1, bmp2):
merged = wx.EmptyBitmap(bmp1.GetWidth(), bmp1.GetHeight())
dc = wx.MemoryDC()
dc.SelectObject(merged)
dc.DrawBitmap(bmp1, 0, 0, True)
dc.DrawBitmap(bmp2, 0, 0, True)
dc.SelectObject(wx.NullBitmap)
return merged
Code: Alles auswählen
import wx
USE_GENERIC = 0
if USE_GENERIC:
from wx.lib.stattext import GenStaticText as StaticText
from wx.lib.statbmp import GenStaticBitmap as StaticBitmap
else:
StaticText = wx.StaticText
StaticBitmap = wx.StaticBitmap
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
StaticText(self, -1, "This is a wx.StaticBitmap.", (45, 15))
bmp = wx.Bitmap("teststep_python.png")
StaticBitmap(self, -1, bmp, (80, 50), (bmp.GetWidth(), bmp.GetHeight()))
bmp2 = wx.Bitmap("teststep_f.png")
StaticBitmap(self, -1, bmp2, (80, 80), (bmp.GetWidth(), bmp.GetHeight()))
bmp3 = self.mergeBitmaps(bmp,bmp2)
StaticBitmap(self, -1, bmp3, (80, 120), (bmp.GetWidth(), bmp.GetHeight()))
def mergeBitmaps(self, bmp1, bmp2):
merged = wx.EmptyBitmap(bmp1.GetWidth(), bmp1.GetHeight())
dc = wx.MemoryDC()
dc.SelectObject(merged)
dc.DrawBitmap(bmp1, 0, 0, True)
dc.DrawBitmap(bmp2, 0, 0, True)
dc.SelectObject(wx.NullBitmap)
return merged
if __name__ == '__main__':
import sys,os
app = wx.App(redirect=False)
window = TestPanel()
window.Show()
app.MainLoop()