Hi All,
I'm working on a rendering engine. It creates a small image from an XML file then draws it on a wx.DC. The problem is speed. I decided to create a cache of the rendered images. I would like to store them in wx.Bitmap instances. First I render the XML onto a wx.MemoryDC, then I blit the MemoryDC onto the target DC. Next time I'll only take the saved bitmap from the cache and blit it on the target DC. Some code:
def Render(self,dc,parsed_xml,clientrect,draw=True):
if self.incache(parsed_xml):
return self.drawfromcache(box,dc,clientrect,draw)
else:
# Create a MemoryDC
mdc = wx.MemoryDC()
bmp = wx.EmptyBitmap(clientrect[2],clientrect[3],32)
mdc.SelectObject(bmp) # Render the XML onto the memorydc
mdc.BeginDrawing()
try:
self.dc = mdc
res = self.RenderBox(parsed_xml,clientrect,draw)
finally:
mdc.EndDrawing()
# Save it into the cache
self.pushtocache(parsed_xml,clientrect,mdc,bmp)
# Draw it on the real dc dc.BeginDrawing()
try:
dc.Blit(
clientrect[0],clientrect[1],clientrect[2],clientrect[3],
mdc,0,0,useMask=True
)
finally:
mdc.EndDrawing() mdc.SelectObject(wx.NullBitmap)
return res
I created the bitmap in 32bit mode. I'm not sure if wx.EmptyBitmap will create a transparent bitmap or not. However, when I use Blit, it draws black pixels where it should be transparent. I tried to set the useMake parameter to True, but apparently this has no effect. I'm also not sure how to use masks in 32 bit mode. I suspect the mask and the alpha channel is not the same. Thanks,
Les