[wxPython-users] capturing contents of wxWindow into an image

Robin Dunn robin at alldunn.com
Wed Aug 1 13:42:21 PDT 2007


Grzegorz Adam Hankiewicz wrote:
> Keefe, Dan C wrote:
>>
>> Hi,
>>
>>  
>>
>> Is there a way to programmatically capture the contents of a wxWindow 
>> into an image file?  The only device context I have to work with is a 
>> wxPaintDC which is not buffered.  The device context goes out of scope 
>> after the OnPaint method goes out of scope.
>>
>>  
>>
>> In a nutshell, I need a way to program taking a screen snapshot for a 
>> defined region within a wxWindow.
>>
> 
> Hmmm... see if the code at http://wiki.wxpython.org/WorkingWithImages 
> for the screen capture will work for you.
> 

Another approach that usually works well is to refactor your OnPaint 
method so the guts of it are split out into another method that takes a 
dc as a parameter.  Then you can create the paint dc in OnPaint and call 
the new method, and when you want to save it to a file you can create a 
memory dc with a bitmap selected into it and call the same method 
passing the memory dc.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list