python - Saving an image of what a device context drew, wxPython -
I need to be able to save an image of the device context canvas (the format does not make any difference). Have tried but this invalid bitmap returns how can I do this?
I believe this should do the trick:
Def saveSnapshot (dcSource): # based on wxpython by Andrew Gavana- Users # 2006-11-08 size = dcSource.Size # Create a bitmap that will hold the screenshot image later # Note Make sure that the bitmap screenshot # 1 is a big size to catch, which means that the current default color depth is BMP = wx.EmptyBitmap (size.width, size.height) # Make the memory of the DC Which will actually be used to take the screenshot memDC = wx. Tell us how to use the memory DC to use our bitmap. # Memory will go to all drawing action bitmaps on DC now memDC.SelectObject (BMP) #Blit ( In this case copy) the actual screen on memory DC # and thus copy the bitmap memDC.Blit (0, # in the X coordinate 0, copy this into # Y coordinate size, # come to this width Copy the car. Hey, copy this height to dcSource, #Where do we copy? 0, # What is the x offset in the original DC? 0 # What is Y offset in the original DC? #) # A new #deflected bitmap memDC Select the bitmap out of memory DC by selecting the Selection Object (wx.NullBitmap) img = bmp.ConvertToImage () img.SaveFile ('saved.png', wx.BITMAP_TYPE_PNG).
(I just had a link to the original, but could not get it quickly.)
Comments
Post a Comment