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.
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 mashtaliryurko@gmail.com 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-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I am using Ubuntu 16.04, wxpython Phoenix 3.0.3, python 3.6
I attached sample app which should do.
scratch_5.py (576 Bytes)
···
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 mashtal...@gmail.com 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.
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 mashtaliryurko@gmail.com 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 mashtal...@gmail.com 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 wxpython-users+unsubscribe@googlegroups.com.
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
Chris.Barker@noaa.gov
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: Multiple screenshots using ScreenDC issue · Issue #259 · wxWidgets/Phoenix · GitHub
···
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.