Multiple screenshots using ScreenDC

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multiple screenshots using ScreenDC

Yurii Mashtalir
Hello everybody

I ran into a problem with ScreenDC. 
My tool is supposed to take multiple screenshots with some period. But whenever I use ScreenDC to grab a screenshot and save it to PNG it works well only for the first time. All the following times it just saves the same image as the first one. To get a new image, I have to restart the program, which is not an option in my case.

The code I used:

size = wx.ScreenDC().GetSize() 
width = size[0] 
height = size[1] 
bmp = wx.Bitmap(width, height) 
mem = wx.MemoryDC(bmp) 
mem.Blit(0, 0, width, height, wx.ScreenDC(), 0, 0) 
bmp.SaveFile('temp.png', wx.BITMAP_TYPE_PNG)

Thanks.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple screenshots using ScreenDC

Chris Barker - NOAA Federal
Due to platform differences, this could be fragile -- Screen and Client DCs are more made for drawing to than pulling from. 

Nevertheless, it at least somewhat working, so ....

You do create a new ScreenDC each time, so pretty strange. I think you'll need to put this in the context of a minimal app so we can see how and when it is called. 

Also -- what platform and version?

One more note -- you are creating a D.C. To get the size, and then again to blit from it. Better to create it and assign it a variable, then query its size, then use it to blit.

-CHB

On Mar 22, 2017, at 8:28 AM, Yurii Mashtalir <[hidden email]> wrote:

Hello everybody

I ran into a problem with ScreenDC. 
My tool is supposed to take multiple screenshots with some period. But whenever I use ScreenDC to grab a screenshot and save it to PNG it works well only for the first time. All the following times it just saves the same image as the first one. To get a new image, I have to restart the program, which is not an option in my case.

The code I used:

size = wx.ScreenDC().GetSize() 
width = size[0] 
height = size[1] 
bmp = wx.Bitmap(width, height) 
mem = wx.MemoryDC(bmp) 
mem.Blit(0, 0, width, height, wx.ScreenDC(), 0, 0) 
bmp.SaveFile('temp.png', wx.BITMAP_TYPE_PNG)

Thanks.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple screenshots using ScreenDC

Yurii Mashtalir
I am using Ubuntu 16.04, wxpython Phoenix 3.0.3, python 3.6

I attached sample app which should do.

On Wednesday, March 22, 2017 at 5:49:49 PM UTC+2, Chris Barker - NOAA Federal wrote:
Due to platform differences, this could be fragile -- Screen and Client DCs are more made for drawing to than pulling from. 

Nevertheless, it at least somewhat working, so ....

You do create a new ScreenDC each time, so pretty strange. I think you'll need to put this in the context of a minimal app so we can see how and when it is called. 

Also -- what platform and version?

One more note -- you are creating a D.C. To get the size, and then again to blit from it. Better to create it and assign it a variable, then query its size, then use it to blit.

-CHB

On Mar 22, 2017, at 8:28 AM, Yurii Mashtalir <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="SK3GQZ4-AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mashtal...@...> wrote:

Hello everybody

I ran into a problem with ScreenDC. 
My tool is supposed to take multiple screenshots with some period. But whenever I use ScreenDC to grab a screenshot and save it to PNG it works well only for the first time. All the following times it just saves the same image as the first one. To get a new image, I have to restart the program, which is not an option in my case.

The code I used:

size = wx.ScreenDC().GetSize() 
width = size[0] 
height = size[1] 
bmp = wx.Bitmap(width, height) 
mem = wx.MemoryDC(bmp) 
mem.Blit(0, 0, width, height, wx.ScreenDC(), 0, 0) 
bmp.SaveFile('temp.png', wx.BITMAP_TYPE_PNG)

Thanks.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="SK3GQZ4-AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

scratch_5.py (604 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple screenshots using ScreenDC

Chris Barker - NOAA Federal
well, on OS-X, all screenshots are black :-(

Sorry I can't help here....

-CHB


On Wed, Mar 22, 2017 at 9:09 AM, Yurii Mashtalir <[hidden email]> wrote:
I am using Ubuntu 16.04, wxpython Phoenix 3.0.3, python 3.6

I attached sample app which should do.

On Wednesday, March 22, 2017 at 5:49:49 PM UTC+2, Chris Barker - NOAA Federal wrote:
Due to platform differences, this could be fragile -- Screen and Client DCs are more made for drawing to than pulling from. 

Nevertheless, it at least somewhat working, so ....

You do create a new ScreenDC each time, so pretty strange. I think you'll need to put this in the context of a minimal app so we can see how and when it is called. 

Also -- what platform and version?

One more note -- you are creating a D.C. To get the size, and then again to blit from it. Better to create it and assign it a variable, then query its size, then use it to blit.

-CHB

On Mar 22, 2017, at 8:28 AM, Yurii Mashtalir <[hidden email]> wrote:

Hello everybody

I ran into a problem with ScreenDC. 
My tool is supposed to take multiple screenshots with some period. But whenever I use ScreenDC to grab a screenshot and save it to PNG it works well only for the first time. All the following times it just saves the same image as the first one. To get a new image, I have to restart the program, which is not an option in my case.

The code I used:

size = wx.ScreenDC().GetSize() 
width = size[0] 
height = size[1] 
bmp = wx.Bitmap(width, height) 
mem = wx.MemoryDC(bmp) 
mem.Blit(0, 0, width, height, wx.ScreenDC(), 0, 0) 
bmp.SaveFile('temp.png', wx.BITMAP_TYPE_PNG)

Thanks.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple screenshots using ScreenDC

Yurii Mashtalir
In reply to this post by Yurii Mashtalir
Still couldn't resolve the issue, but when I run this code on python 2 and wxPython Classic, it works well(just using EmptyBitmap instead of Bitmap).

Seems to be the problem of wxPython Phoenix only. Reported issue here: https://github.com/wxWidgets/Phoenix/issues/259

On Wednesday, March 22, 2017 at 5:28:11 PM UTC+2, Yurii Mashtalir wrote:
Hello everybody

I ran into a problem with ScreenDC. 
My tool is supposed to take multiple screenshots with some period. But whenever I use ScreenDC to grab a screenshot and save it to PNG it works well only for the first time. All the following times it just saves the same image as the first one. To get a new image, I have to restart the program, which is not an option in my case.

The code I used:

size = wx.ScreenDC().GetSize() 
width = size[0] 
height = size[1] 
bmp = wx.Bitmap(width, height) 
mem = wx.MemoryDC(bmp) 
mem.Blit(0, 0, width, height, wx.ScreenDC(), 0, 0) 
bmp.SaveFile('temp.png', wx.BITMAP_TYPE_PNG)

Thanks.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...