Discussion:
drawing on screen and saving it to image
Anna Petrášová
2014-09-30 21:22:50 UTC
Permalink
Hi all,

I would like to create a tool for drawing on screen with mouse to annotate
any application and then save the annotations as an image (something
similar to Ardesia, just simpler). I was searching online and I found
basically three possibilities - using wx.ScreenDC, drawing on transparent
frame or ShapedWindow. I was doing some very preliminary tests and I was
not able to get anything usable so far. The wx.ScreenDC looked promising
but the drawing disappears immediately. The transparent frame makes
transparent also the drawing which I don't want. The ShapedWindow seems to
allow to draw only on the not transparent part. So I was wondering if you
have any idea what could be the right approach. I need it mostly for
Windows platform.

Thanks for any advice.

Anna
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Roberts
2014-10-01 17:46:03 UTC
Permalink
Post by Anna Petrášová
I would like to create a tool for drawing on screen with mouse to
annotate any application and then save the annotations as an image
(something similar to Ardesia, just simpler). I was searching online
and I found basically three possibilities - using wx.ScreenDC, drawing
on transparent frame or ShapedWindow. I was doing some very
preliminary tests and I was not able to get anything usable so far.
The wx.ScreenDC looked promising but the drawing disappears
immediately. The transparent frame makes transparent also the drawing
which I don't want. The ShapedWindow seems to allow to draw only on
the not transparent part. So I was wondering if you have any idea what
could be the right approach.
wx.ScreenDC will allow you to draw on any portion of the desktop, but
since you don't have a window over the top, it doesn't keep focus. When
you click the mouse to start drawing, the app you're drawing on will get
the mouse click and motion messages.

It seems to me that the only practical way to do this is to grab a
screenshot of the entire screen, then have your app come up as a normal
full-screen window without borders. Display the screenshot, and let the
user draw on it like a normal paint application. That way, you're in
complete control, and the background applications won't interfere. It
does mean you won't see any updates should the background windows change.

If you really want the drawing to be relative to another application,
has it occurred to you that you will need to track the window location
and size of application you're drawing on, so you can make all of the
drawing relative to that window?
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tim Roberts
2014-10-03 17:02:02 UTC
Permalink
Post by Tim Roberts
Post by Anna Petrášová
I would like to create a tool for drawing on screen with mouse to
annotate any application and then save the annotations as an image
(something similar to Ardesia, just simpler). ...
...
It seems to me that the only practical way to do this is to grab a
screenshot of the entire screen, then have your app come up as a normal
full-screen window without borders.
For what it's worth, the scheme I described is exactly how the "snipping
tool" in Windows 7 works. It grabs a screen shot of the entire desktop,
and then you work with that static snapshot. Anything that changes
while you're working is not reflected.

I'm not sure you could do it any other way. You are liable to make
things very difficult for the user if he can SEE a window, but he can't
click on the buttons or type text because your transparent window is on
top. That's why the snipping tool changes the screen contrast -- it
makes it obvious that you're not live.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-10-03 17:18:48 UTC
Permalink
Post by Tim Roberts
Post by Tim Roberts
Post by Anna Petrášová
I would like to create a tool for drawing on screen with mouse to
annotate any application and then save the annotations as an image
(something similar to Ardesia, just simpler). ...
...
It seems to me that the only practical way to do this is to grab a
screenshot of the entire screen, then have your app come up as a normal
full-screen window without borders.
For what it's worth, the scheme I described is exactly how the "snipping
tool" in Windows 7 works. It grabs a screen shot of the entire desktop,
and then you work with that static snapshot. Anything that changes
while you're working is not reflected.
I'm not sure you could do it any other way. You are liable to make
things very difficult for the user if he can SEE a window, but he can't
click on the buttons or type text because your transparent window is on
top.
That was my thinking for why you'd want to use a shaped window, it would
fail if a user drew all over the buttons though... you could literally
cross-out buttons by drawing on top of them... which might be a fun trick
to play on someone :D
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chris Barker - NOAA Federal
2014-10-01 19:07:25 UTC
Permalink
On Sep 30, 2014, at 2:23 PM, "Anna Petrášová" <***@gmail.com> wrote:

Hi all,

I would like to create a tool for drawing on screen with mouse to annotate
any application and then save the annotations as an image


So you want to draw on top of other applications? Interesting..

- using wx.ScreenDC,


That's probably the way to go,

drawing on transparent frame


That also may work, it depends some on the UI you want. And what you can
get to work...

The wx.ScreenDC looked promising but the drawing disappears immediately.


You might try:

Drawing to a MemoryDC, then drawing That to a screenDC -- that way you can
save the contents of the bitmap associated with the MemoryDC. And easily
re-draw it to the screen DC when it needs to be refreshed.

Not that I've ever tried anything like that...

You could also save a vector representation if what is drawn that you can
then re-render to the Screen,DC when needed, and render to a MemoryDC when
you want to save it.

One trick is knowing when you need to re- draw -- you probably don't get a
PaintEvent when stuff needs refreshing outside your app's Windows.

HTH,

Chris

The transparent frame makes transparent also the drawing which I don't
want. The ShapedWindow seems to allow to draw only on the not transparent
part. So I was wondering if you have any idea what could be the right
approach. I need it mostly for Windows platform.

Thanks for any advice.

Anna
--
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+***@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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-10-01 21:00:27 UTC
Permalink
Post by Anna Petrášová
Hi all,
I would like to create a tool for drawing on screen with mouse to annotate
any application and then save the annotations as an image (something
similar to Ardesia, just simpler). I was searching online and I found
basically three possibilities - using wx.ScreenDC, drawing on transparent
frame or ShapedWindow.
Seems like ShapedWindow might be able to be combined with wx.STAY_ON_TOP...
have a button in your application that turns on and off drawing, when
drawing is on and MOUSE_DOWN happens, find the window under the cursor
(likely OS dependent calls needed) and create a bitmap the size of that
window (on Windows I guess you'd track the HWND) and also a Frame (Shaped)
if you don't already have one stored for it.

Then as the ShapedWindow demo does, perform this on the new frame with you
drawn-on bitmap:
# Use the bitmap's mask to determine the region
r = wx.RegionFromBitmap(self.bmp)
self.hasShape = self.SetShape(r)

Then you'll need to have a thread I guess that runs and watches all the
windows you drew on to see if they moved, and also if they got
expanded/resized (not sure if you would want to increase/crop or scale the
image), and probably also what Z-index or Z-height the Window is at (so
your drawing is hidden when another window is dragged on top).

Pretty cool idea!
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
annakrat
2014-10-03 02:49:32 UTC
Permalink
Post by Nathan McCorkle
Post by Anna Petrášová
Hi all,
I would like to create a tool for drawing on screen with mouse to
annotate any application and then save the annotations as an image
(something similar to Ardesia, just simpler). I was searching online and I
found basically three possibilities - using wx.ScreenDC, drawing on
transparent frame or ShapedWindow.
Seems like ShapedWindow might be able to be combined with
wx.STAY_ON_TOP... have a button in your application that turns on and off
drawing, when drawing is on and MOUSE_DOWN happens, find the window under
the cursor (likely OS dependent calls needed) and create a bitmap the size
of that window (on Windows I guess you'd track the HWND) and also a Frame
(Shaped) if you don't already have one stored for it.
Then as the ShapedWindow demo does, perform this on the new frame with you
# Use the bitmap's mask to determine the region
r = wx.RegionFromBitmap(self.bmp)
self.hasShape = self.SetShape(r)
Then you'll need to have a thread I guess that runs and watches all the
windows you drew on to see if they moved, and also if they got
expanded/resized (not sure if you would want to increase/crop or scale the
image), and probably also what Z-index or Z-height the Window is at (so
your drawing is hidden when another window is dragged on top).
Pretty cool idea!
Thanks all for your ideas, too bad nobody actually did anything like that.
It seems the result would be quite unsure, I have to give it a thought,

Cheers,

Anna
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-10-03 16:33:13 UTC
Permalink
Post by Nathan McCorkle
Post by Anna Petrášová
Hi all,
I would like to create a tool for drawing on screen with mouse to
annotate any application and then save the annotations as an image
(something similar to Ardesia, just simpler). I was searching online and I
found basically three possibilities - using wx.ScreenDC, drawing on
transparent frame or ShapedWindow.
Seems like ShapedWindow might be able to be combined with
wx.STAY_ON_TOP... have a button in your application that turns on and off
drawing, when drawing is on and MOUSE_DOWN happens, find the window under
the cursor (likely OS dependent calls needed) and create a bitmap the size
of that window (on Windows I guess you'd track the HWND) and also a Frame
(Shaped) if you don't already have one stored for it.
Then as the ShapedWindow demo does, perform this on the new frame with you
# Use the bitmap's mask to determine the region
r = wx.RegionFromBitmap(self.bmp)
self.hasShape = self.SetShape(r)
P.S. I said to do it this way, so that interacting with the drawn-on window
isn't blocked by a non-shaped but transparent window/frame with your
drawing bitmap.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...