[Lazarus] Transparent (key color based) drawing questions

Flávio Etrusco flavio.etrusco at gmail.com
Thu Jul 14 18:03:29 CEST 2011


On Thu, Jul 14, 2011 at 7:37 AM, Max Vlasov <max.vlasov at gmail.com> wrote:
> Hi,
> I used the technique described here
>  http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Drawing_color_transparent_bitmaps
> for transparent drawing on windows. So when porting to cross-platform
> used this example.
>
> Two observations:
>
> 1. At least on linux gtk the order of assignments should be reverse
>
> On the site
>  bmp.Transparent := True;
>  bmp.TransparentColor := clFuchsia;
>
> But the correct order is
>  bmp.TransparentColor := clFuchsia;
>  bmp.Transparent := True;
>
> because probably in the first case the color assignment invalidates
> Masked (= Transparent). Seems like every next call is ok because the
> mask is already created. If my case when the program started, the
> result was non-transparent, and the problem is fixed only when I
> mimimize and restore the window
>
> Either it would be great to fix this in the example (mentioning this
> side effect in the comment) or change the code to be more universal.
>

What's the exact code? Can you debug and check TGraphic.Changed is
being called after TransparentColor is invoked in the first example?
Looking at the TRasterImage code, SetTransparent always invoke
Changed, but SetTransparentColor has a more complex handling.
Anyway I agree it's worth changing the wiki; the mask generation is
delayed until it's needed, so the order won't make a difference in the
example, but depending on what's done in OnChange it can easily
trigger the mask generation twice.

Best regards,
Flávio




More information about the Lazarus mailing list