Drawing a transparent box onto an image control

I have an application where I have a static bitmap (for an image
control) upon which I want to draw a transparent box so the user can
select a subimage. The desire is for the border of the transparent
box to be visible of course, so the user can tell what has been
selected.

I have tried using a wx.PaintDC (with the image control as the parent)
with which to draw the box. The problem I encounter is that the
underlying image is now hidden. I have tried wx.PaintDC, wx.GCDC,
wx.GraphicsContext, using wx.TRANSPARENT flag, etc, etc. with no
luck. I have searched wxPython demo for examples, but have found
nothing that resolves upon implementing. ???

I have an application where I have a static bitmap (for an image
control) upon which I want to draw a transparent box

Just thinking out loud, you could just draw lines for the box and
scale them based on cursor position away from the triggering event.
so the user can

···

On Wed, Feb 29, 2012 at 5:36 PM, Tim N <tanichdesenich@gmail.com> wrote:

select a subimage. The desire is for the border of the transparent
box to be visible of course, so the user can tell what has been
selected.

I have tried using a wx.PaintDC (with the image control as the parent)
with which to draw the box. The problem I encounter is that the
underlying image is now hidden. I have tried wx.PaintDC, wx.GCDC,
wx.GraphicsContext, using wx.TRANSPARENT flag, etc, etc. with no
luck. I have searched wxPython demo for examples, but have found
nothing that resolves upon implementing. ???

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

There are two ways that rubber-banding is typically done in wx. The first technique is to draw a rectangle in response to the appropriate mouse events using the wx.INVERT logical function. That will cause the existing pixels to be combined with those to be drawn for the rectangle in such a way that if you draw the rectangle a 2nd time that the original pixels will be restored. So when the mouse is dragged a little further and you are ready to draw the next rectangle you will want to first redraw the previous rectangle to erase it.

The second technique uses the wx.Overlay classes to get the DC to draw the rectangle upon. It will automatically maintain the image of what was already drawn on the window when the use of the overlay starts, and will restore it when done, so it is a good way to handle temporary things like a rubber-banding box, especially when you want it to be more fancy than just an inverted rectangle. There were some discussions here about overlays a few weeks ago, including some examples that will show you how to use them.

···

On 2/29/12 2:36 PM, Tim N wrote:

I have an application where I have a static bitmap (for an image
control) upon which I want to draw a transparent box so the user can
select a subimage. The desire is for the border of the transparent
box to be visible of course, so the user can tell what has been
selected.

I have tried using a wx.PaintDC (with the image control as the parent)
with which to draw the box. The problem I encounter is that the
underlying image is now hidden. I have tried wx.PaintDC, wx.GCDC,
wx.GraphicsContext, using wx.TRANSPARENT flag, etc, etc. with no
luck. I have searched wxPython demo for examples, but have found
nothing that resolves upon implementing. ???

--
Robin Dunn
Software Craftsman

As I recall, the Whyteboard application has an example of one of the rubber band techniques. It might be worth taking a look at: http://whyteboard.org/

  • Mike
···

On Thursday, March 1, 2012 11:38:45 AM UTC-6, Robin Dunn wrote:

On 2/29/12 2:36 PM, Tim N wrote:

I have an application where I have a static bitmap (for an image
control) upon which I want to draw a transparent box so the user can
select a subimage. The desire is for the border of the transparent
box to be visible of course, so the user can tell what has been
selected.

I have tried using a wx.PaintDC (with the image control as the parent)
with which to draw the box. The problem I encounter is that the
underlying image is now hidden. I have tried wx.PaintDC, wx.GCDC,
wx.GraphicsContext, using wx.TRANSPARENT flag, etc, etc. with no
luck. I have searched wxPython demo for examples, but have found
nothing that resolves upon implementing. ???