Skip to content

Instantly share code, notes, and snippets.

@JonasPf
Created July 15, 2014 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonasPf/e3c1447e2333b982788d to your computer and use it in GitHub Desktop.
Save JonasPf/e3c1447e2333b982788d to your computer and use it in GitHub Desktop.
wxPython: Create and save bitmap
w = 500
h = 300
bmp = wx.EmptyBitmap(w, h)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush('black'))
dc.Clear()
dc.SetBrush(wx.Brush('green'))
dc.SetPen(wx.Pen('red', width=1))
dc.DrawRectangle(10,10,w-10,h-10)
dc.SelectObject(wx.NullBitmap)
bmp.SetMaskColour('black')
img = bmp.ConvertToImage()
img.SaveFile('saved.png', wx.BITMAP_TYPE_PNG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment