Problem when using MemoryDC

Why is my code printing lines of gray instead of black?

import wx

class MyFrame(wx.Frame):
    def __init__(self,*args,**kwargs):
        wx.Frame.__init__(self,*args,**kwargs)
        self.panel=wx.Panel(self,-1,size=(1000,1000))
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)

        self.bitmap=wx.EmptyBitmapRGBA(1000,1000,255,255,255,255)

        dc=wx.MemoryDC()
        dc.SelectObject(self.bitmap)
        dc.SetPen(wx.Pen(wx.NamedColor("black"),10,wx.SOLID))
        dc.DrawCircle(0,0,30)
        dc.DrawLine(40,40,70,70)
        dc.Destroy()

        self.Show()

    def on_size(self,e=None):
        self.Refresh()

    def on_paint(self,e=None):
        dc=wx.PaintDC(self.panel)
        dc.DrawBitmap(self.bitmap,0,0)
        dc.Destroy()

if __name__=="__main__":
    app=wx.PySimpleApp()
    my_frame=MyFrame(parent=None,id=-1)
    app.MainLoop()

      

+1


a source to share


2 answers


Apart from the paint / paint panel issue, it has already been pointed out that the color issue is related to the alpha channel of the 32 bit bitmap.



I remember reading to use wx.GCDC

instead wx.DC

.

+1


a source


Ok I tested the new wx version (2.8.9.2)

and now i wonder why it even works on your side. you are trying to draw the panel, but overriding the frame draw event

do this instead



self.panel.Bind(wx.EVT_PAINT, self.on_paint)

      

and all will be well

0


a source







All Articles