Shaped window from transparent part of bitmap

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Shaped window from transparent part of bitmap

Torsten

I have a bitmap with a transparent part. This bitmap is painted multiple times in the frame. How can i use the transparent part of the bitmap to build a shape for the window. I've attached a sample that should demonstrate what i want to achieve. The sample uses given values for the sahpe, but my final code doesn't know them.

--
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.

shaped.py (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Shaped window from transparent part of bitmap

Rufus V. Smith

On Sep 10, 2017, at 9:33 AM, 'Torsten' via wxPython-users <[hidden email]> wrote:


I have a bitmap with a transparent part. This bitmap is painted multiple times in the frame. How can i use the transparent part of the bitmap to build a shape for the window. I've attached a sample that should demonstrate what i want to achieve. The sample uses given values for the sahpe, but my final code doesn't know them.

-- 
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.
<shaped.py>

Hi Torsten,

For additional clarification, it appears to me you wish to create a fixed width border around an arbitrary
graphic shape in Python (which has been provided to you in a bitmap surrounded by a transparent area).

        Like coating a strawberry with chocolate and looking at the cross-section, you want an algorithm to
generate that chocolate area.

Is that the idea?

Rufus

--
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
|

Re: Shaped window from transparent part of bitmap

Torsten
Hello Rufus,

no, i want a wx.Frame() that has no border and no background (like totally transparent), but only the frame. Buttons and pictures that i place inside should be fully visible. From my reading this is done with wx.frame.SetShape(wx.RegionFromBitmap(bmp)). The bmp is a black/white bitmap. The black part will be the transparent part of the frame (shape). For buttons i can easily get the position and size and paint a white rectangle on black ground. But the picture is my problem.

I have this:


And i want that:


What in the initial picture is transparent should be black, all other colours should be white.


I hope now is clear what goal is. :)

--
Torsten

--
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
|

Re: Shaped window from transparent part of bitmap

Chris Barker - NOAA Federal
On Mon, Sep 11, 2017 at 10:18 AM, 'Torsten' via wxPython-users <[hidden email]> wrote:
no, i want a wx.Frame() that has no border and no background (like totally transparent), but only the frame. Buttons and pictures that i place inside should be fully visible. From my reading this is done with wx.frame.SetShape(wx.RegionFromBitmap(bmp)). The bmp is a black/white bitmap. The black part will be the transparent part of the frame (shape). For buttons i can easily get the position and size and paint a white rectangle on black ground. But the picture is my problem.

I have this:


And i want that:


What in the initial picture is transparent should be black, all other colours should be white.

Do you actually need a circle? or that a simple example? If circle, then you can easily do that by makign a black rectangle and drawing a white circle on it with a wx.MemoryDC.

But I suspect that you have an "arbitrary" image.

wxBitmap has essentiually no functionality, but wxImage does have some basic Image processing -- maybe:

wxImage.Replace() can help.

Or, for more robust functionality, use the PIL or numpy. -- you can convert to/from PIL images or numpy arrays pretty efficiently:


(kind old page, but I hope most of it works)

-CHB


--

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
|

Re: Shaped window from transparent part of bitmap

Torsten
Yes, the circle is just an example. It can be a more 'complex' figure. I'll take a look at PIL. 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
|

Re: Shaped window from transparent part of bitmap

Robin Dunn
In reply to this post by Torsten

On Monday, September 11, 2017 at 10:18:45 AM UTC-7, Torsten wrote:
Hello Rufus,

no, i want a wx.Frame() that has no border and no background (like totally transparent), but only the frame. Buttons and pictures that i place inside should be fully visible. From my reading this is done with wx.frame.SetShape(wx.RegionFromBitmap(bmp)). The bmp is a black/white bitmap. The black part will be the transparent part of the frame (shape). For buttons i can easily get the position and size and paint a white rectangle on black ground. But the picture is my problem.
 

What in the initial picture is transparent should be black, all other colours should be white.


IIUC, one approach that comes to mind is to get the region from the original bitmap, create a new bitmap of the correct size and set it into a MemoryDC. Then clear the DC with a black brush, then do SetDeviceClippingRegion with the original bitmap's transparent region, and then clear the DC with white.

If you need to combine multiple source bitmaps and get the remaining transparent space as a region, then another approach would be to fill a target bitmap & MemoryDC with a color you know is not in any of the sources, draw the sources to the bitmap, and then use SetMaskColour to set the target bitmap's mask to include every pixel with that colour.  Then you can use that bitmap to extract the region to be used to set the frame's shape.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
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
|

Re: Shaped window from transparent part of bitmap

Rufus V. Smith

On Monday, September 11, 2017 at 10:18:45 AM UTC-7, Torsten wrote:
Hello Rufus,

no, i want a wx.Frame() that has no border and no background (like totally transparent), but only the frame. Buttons and pictures that i place inside should be fully visible. From my reading this is done with wx.frame.SetShape(wx.RegionFromBitmap(bmp)). The bmp is a black/white bitmap. The black part will be the transparent part of the frame (shape). For buttons i can easily get the position and size and paint a white rectangle on black ground. But the picture is my problem.
 

What in the initial picture is transparent should be black, all other colours should be white.



I was curious about this technique, because Iiked the effect, even in your demo.

It looks like numpy (found by Google, not by experience) might have functions you could use:


The answers/comments here don't provide an exact solution, but seem to be on the right track.


--
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.