Recent

Author Topic: [SOLVED] Awkward behaviour of BGRABitmap - no antialias, no alpha blending  (Read 2188 times)

DonDan

  • Newbie
  • Posts: 2
First of all I want to thank the author of BGRABitmap for this really powerful component.

Unfortunately I have really strange issue preventing me from actually using the component. I have integrated the component into a sub class that I create dynamically. When I use it there it behaves like any “dumb” standard canvas. I can call the AntiAlias version of the drawing functions and use colors with alpha channels. However it will not perform any of these features, but draw plain non-anti-aliased elements without alpha-blending.

Since I thought this was a general installation issue I copied the relevant code to main-form and tried it there. Strangely it fully works there (with anti-aliasing and alpha-blending). The code is 1:1 the same, to only difference is that it works when called from the main form, but not (properly) when executed within a sub-class created dynamically by the main form. 
Having 20+ years of coding experience I find that behavior quite strange. The only thing I can think of are some “environmental” / global variables of the class, which might somehow cause this different outcome of the same code. However I could not identify what that could be.

One code is executed in a TForm class,  the other in a Tobject class. However it even works when I create the TBGRABitmap in the Tobject class and draw on it in the TForm class – which is even weirder. (I thought that maybe the TBGRABitmap would get different attributes when created in the Tobject class).

Any help or hint on that is appreciated.
Thank you.
« Last Edit: September 20, 2017, 05:17:19 pm by DonDan »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Do this simple exercise, create a small sample that demonstrate your problem and post it here. I wouldn't post the existing tobject but I would recreate it with the minimal code required to show the problem. If I were a betting man I would bet that at this point you will find the problem and solve it your self if not post it here.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

DonDan

  • Newbie
  • Posts: 2
Re: [SOLVED] Awkward behaviour of BGRABitmap - no antialias, no alpha blending
« Reply #2 on: September 20, 2017, 05:30:08 pm »
Embarrassingly, you are right. I did many tests before posting this, however reducing the code to the simplest "postable" demo really helped.
As I broke down the complex code into a small example I could find the bug: the drawing routines within my code where called multiple times on the same canvas. By drawing over and over again the same graphic the alpha-channel gets "saturated" = opaque, hence all transparency - and also the anti-alias effect vanishes, finally resulting in a standard "pixelized" bitmap with no shades.

I'll still leave this post up, just in case anyone else gets trapped.

 

TinyPortal © 2005-2018