dc = wx.MemoryDC(i3)
MASK = (0,0,1) # just an unused color
dc.SetBackground(wx.Brush(MASK))
dc.Clear()
dc.DrawBitmap(i1, 0, 0, True)
dc.DrawBitmap(i2, 0, 0, True)
del dc
pil1.paste( pil2, # image to paste into pil1 (pil1 has its own mask)
(0, 0), # U-L offset into pil1
pil2 ) # use pil2's transparency layer as a mask for pasting.
I've tried every settings combination for dc.Blit() possible with no
success.
See attached file imagefile_combined_with_masks.png
Sample code, source and resultant images are attached.
There seems to be a "chicken and egg problem" in trying to define an
unused color:
To pick an unused color the final bitmap must be formed, but this
"unused color" must be defined *before* drawing the final bitmap in
order to define the mask color !
Can the transparency in the original image files be used to form the
final transparency mask and avoid this poultry problem ?
···
On Jun 14, 10:21 pm, Robin Dunn <ro...@alldunn.com> wrote:
On 6/12/10 7:18 PM, Ray Pasco wrote:
> How can I get wx to accomplish this Pil method:
> pil1.paste( pil2, # image to paste into pil1 (pil1 has its own mask)
> (0, 0), # U-L offset into pil1
> pil2 ) # use pil2's transparency layer as a mask for pasting.
> I've tried every settings combination for dc.Blit() possible with no
> success.
> See attached file imagefile_combined_with_masks.png
> Sample code, source and resultant images are attached.
> Thanks in advance
There are likely other ways, but this is the first that popped into my
head, and it works:
dc = wx.MemoryDC(i3)
MASK = (0,0,1) # just an unused color
dc.SetBackground(wx.Brush(MASK))
dc.Clear()
dc.DrawBitmap(i1, 0, 0, True)
dc.DrawBitmap(i2, 0, 0, True)
del dc
There seems to be a "chicken and egg problem" in trying to define an
unused color:
To pick an unused color the final bitmap must be formed, but this
"unused color" must be defined *before* drawing the final bitmap in
order to define the mask color !
You could convert the source bitmaps to wx.Image and use FindFirstUnusedColour or get the colour it is already using to represent the mask with GetMaskRed|Green|Blue.
Can the transparency in the original image files be used to form the
final transparency mask and avoid this poultry problem ?
Yes, something like this would probably work:
* Create a wx.Region for each of the source bitmaps using the bimap's mask, using wx.RegionFromBitmap.
* Add one region to the other with region1.UnionRegion(region2)
* Convert the result to a wx.Bitmap with region1.ConvertToBitmap()
* Create a wx.Mask from that bitmap and assign it to the bitmap that holds the results of the drawing, with SetMask.