Problem with alphablending in the new Graphics Context

Hi list,

I’m trying to draw 2 PNGs on a GraphicsContext MemoryDC

    pdc = wx.PaintDC(self)
    mdc = wx.MemoryDC(wx.EmptyBitmap(900,600))
    gc = wx.GCDC(mdc)
    gc.DrawBitmap

(self.bkg, 0, 0)
gc.DrawBitmap(self.nr, 68, 277, True)
gc.DrawBitmap(self.nl, 373, 277, True)

unfortunately the alphablending information is not used properly and in the resulting image the blend of the bitmaps (nr and nl) is done with black instead of the actual background.

WARNING: the screenshots might not be safe for work in some places (full frontal nudity)
http://cms.ro/vs.jpg
If I’m doing the drawing directly on the PaintDC the blending is OK BUT I lose the Double Buffering.
here is how the image looks if I move the drawing after the blit of the MemoryDC image

    pdc.Blit(0,0,900,600, mdc, 0,0)
    pdc.DrawBitmap([self.nr](http://self.nr), 68, 277, True)
    pdc.DrawBitmap([self.nl](http://self.nl), 373, 277, True)


http://cms.ro/vs2.jpg

Is this a bug in the GCDC code or am I doing something wrong? What can I try?

I’m using the latest preview (2.8.1.2.20070209) on Windows SP2, python 2.4
Thank you in advance.

Peter.

···


There is NO FATE, we are the creators.

Hi list,

I'm trying to draw 2 PNGs on a GraphicsContext MemoryDC

        pdc = wx.PaintDC(self)
        mdc = wx.MemoryDC(wx.EmptyBitmap(900,600))
        gc = wx.GCDC(mdc)
        gc.DrawBitmap (self.bkg, 0, 0)
        gc.DrawBitmap(self.nr, 68, 277, True)
        gc.DrawBitmap(self.nl, 373, 277, True)

unfortunately the alphablending information is not used properly and in the
resulting image the blend of the bitmaps (nr and nl) is done with black
instead of the actual background.
WARNING: the screenshots might not be safe for work in some places (full
frontal nudity)
http://cms.ro/vs.jpg
If I'm doing the drawing directly on the PaintDC the blending is OK BUT I
lose the Double Buffering.
here is how the image looks if I move the drawing after the blit of the
MemoryDC image

        pdc.Blit(0,0,900,600, mdc, 0,0)
        pdc.DrawBitmap(self.nr, 68, 277, True)
        pdc.DrawBitmap(self.nl, 373, 277, True)

http://cms.ro/vs2.jpg

Is this a bug in the GCDC code or am I doing something wrong? What can I
try?

Does it work if you use DrawBitmap directly from the memory DC,
without the GCDC wrapper? As far as I know plain old wxDC supports
alpha in images.

···

On 2/13/07, Peter Damoc <pdamoc@gmail.com> wrote:

I'm using the latest preview (2.8.1.2.20070209) on Windows SP2, python 2.4
Thank you in advance.
Peter.
--
There is NO FATE, we are the creators.

Hi Chris,

Yes, using the simple MemoryDC I get the right alphablending BUT no more nice antialiased lines :o)

Peter

···

On 2/13/07, Chris Mellon arkanes@gmail.com wrote:

Does it work if you use DrawBitmap directly from the memory DC,
without the GCDC wrapper? As far as I know plain old wxDC supports
alpha in images.


There is NO FATE, we are the creators.

> Does it work if you use DrawBitmap directly from the memory DC,
> without the GCDC wrapper? As far as I know plain old wxDC supports
> alpha in images.

Hi Chris,

Yes, using the simple MemoryDC I get the right alphablending BUT no more
nice antialiased lines :o)

If I understand correctly then, it's not just drawing the bitmaps
thats the problem, but also
drawing your lines on top of the bitmap? The alpha blending in the
lines uses black instead of the image background?

In that case, I'd suggest trying a different approach. Blend the
background, nl, and nr bitmaps together in a memory DC and blit to the
paint dc. Then create a GCDC on top of the paint dc, and draw your
lines there. If you cache a GraphicsPath object and just call
StrokePath it should be very fast, with minimal/0 flicker.

···

On 2/13/07, Peter Damoc <pdamoc@gmail.com> wrote:

On 2/13/07, Chris Mellon <arkanes@gmail.com> wrote:

Peter
--
There is NO FATE, we are the creators.

Peter Damoc wrote:

WARNING: the screenshots might not be safe for work in some places (full frontal nudity)

Thanks for the warning.

Is this a bug in the GCDC code or am I doing something wrong?

I expect that it's a bug. I've informed Stefan about it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

If I understand correctly then, it’s not just drawing the bitmaps
thats the problem, but also
drawing your lines on top of the bitmap? The alpha blending in the
lines uses black instead of the image background?

No, the problem is only with the bitmaps. What I failed to express is that if I don’t use the GCDC (and use only the MemoryDC) the lines will be jagged and there will be no semi-transparency in brushes.

In that case, I’d suggest trying a different approach. Blend the
background, nl, and nr bitmaps together in a memory DC and blit to the

paint dc.

This is a very good solution (the one I was looking for). I already convinced my boss to accept a schematic representation of the nipple-areola complex (2 concentric circles) but maybe I can give him a nice surprise tomorrow. :slight_smile:

Thank you for your help Chris.

Peter

···

On 2/13/07, Chris Mellon arkanes@gmail.com wrote:

There is NO FATE, we are the creators.