I am wondering if/how I can use multi-bit transparency masks for
blitting anti-aliased text in a custom cell renderer of a wx.Grid.
Is GraphicsContext the way to go?
Doing a dc.DrawText() should already use anti-aliasing, although IIRC it can be dependent on system configuration settings on some platforms. You may want to check if you're able to get AA text already. I'm not sure if GraphicsContext text drawing is subject to that same configuration setting or not.
How do I replace the standard dc that is provided as Draw method
parameter?
You don't replace it. You set it as the target of the GraphicsContext by using it to create the GC. For example:
dc.DrawText works with AA on my platform. The problem is that it is too
slow. Therefore, I am trying to blit a bitmap with the text to the dc.
Since there already is a background, a transparency mask is required.
This works with a 1 bit mask. However, the AA pixels are visible as a
white aura, which I would like to get rid of. I am looking for a
standard way of blitting AA text inside a wx.Grid.
Martin
···
On Thu, 27 May 2010 09:13:28 -0700 Robin Dunn <robin@alldunn.com> wrote:
Doing a dc.DrawText() should already use anti-aliasing, although IIRC
it can be dependent on system configuration settings on some
platforms. You may want to check if you're able to get AA text
already. I'm not sure if GraphicsContext text drawing is subject to
that same configuration setting or not.
That is because when the bitmap was created it had a white background and so the text was AA blended with that background color, so you end up with partially transparent pixels that range in color between the foreground and background colors. The only way I know of to work around this is to use a bitmap background color that is the same as or close to the color of the window (the grid in this case) where the bitmap will be blitted. That way the non-transparent AA'd pixels will be a closer match to what is already there and the blending will look correct.
Are you creating the bitmaps programatically or with some graphics editor? If the latter then you may be able to get it to do the AA with a fully transparent background, so the result will blend better with all colors when blitted.
···
On 5/27/10 2:40 PM, Martin Manns wrote:
On Thu, 27 May 2010 09:13:28 -0700 > Robin Dunn<robin@alldunn.com> wrote:
Doing a dc.DrawText() should already use anti-aliasing, although IIRC
it can be dependent on system configuration settings on some
platforms. You may want to check if you're able to get AA text
already. I'm not sure if GraphicsContext text drawing is subject to
that same configuration setting or not.
dc.DrawText works with AA on my platform. The problem is that it is too
slow. Therefore, I am trying to blit a bitmap with the text to the dc.
Since there already is a background, a transparency mask is required.
This works with a 1 bit mask. However, the AA pixels are visible as a
white aura, which I would like to get rid of.
Unfortunately, background bitmaps can be user defined and can change
dynamically. The text is drawn programatically. Since the text may
overlap to adjacent cells, the background color is basically unknown.
I am looking for something like blitted layered drawing with
transparencies.
Martin
···
On Fri, 28 May 2010 11:56:25 -0700 Robin Dunn <robin@alldunn.com> wrote:
On 5/27/10 2:40 PM, Martin Manns wrote:
> On Thu, 27 May 2010 09:13:28 -0700
> dc.DrawText works with AA on my platform. The problem is that it is
> too slow. Therefore, I am trying to blit a bitmap with the text to
> the dc. Since there already is a background, a transparency mask is
> required. This works with a 1 bit mask. However, the AA pixels are
> visible as a white aura, which I would like to get rid of.
That is because when the bitmap was created it had a white background
and so the text was AA blended with that background color, so you end
up with partially transparent pixels that range in color between the
foreground and background colors. The only way I know of to work
around this is to use a bitmap background color that is the same as
or close to the color of the window (the grid in this case) where the
bitmap will be blitted. That way the non-transparent AA'd pixels
will be a closer match to what is already there and the blending will
look correct.
Are you creating the bitmaps programatically or with some graphics
editor? If the latter then you may be able to get it to do the AA
with a fully transparent background, so the result will blend better
with all colors when blitted.