Recent

Author Topic: Transparency issue  (Read 4449 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Transparency issue
« on: August 29, 2011, 03:56:51 pm »
Can someone explain me this ?

In attached project, there is TCustomControl derived component containing two bitmaps (TBitmap). I change content of these bitmaps and then I pass them through TMemoryStream to activate transparency.
The left bitmap is displayed correctly always, the right only sometimes.
The only difference is that method Canvas.Clear of the left bitmap is called twice (see line 137).

To reproduce:
1) Start Project
2) Press button to Create
3) Now press many times the second button (each 4-th press it should show the bug (unwanted "relict" blue frame)).

This happens with Qt4 and GTK2.

Thanks.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Transparency issue
« Reply #1 on: August 29, 2011, 04:42:39 pm »
It's bugging with Windows 7 32-bit too.

Will it work if you replace all Canvas.Clear; with rectangle drawing command? If i recall Delphi's canvas didn't even have Clear function and i have never used that with drawing.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Transparency issue
« Reply #2 on: August 29, 2011, 05:01:18 pm »
Thanks.

I replaced Canvas.Clear; with FillRect(0, 0, Width, Height); and now it works.

Canvas.Clear is implemented:
Code: [Select]
procedure TFPCustomCanvas.Clear;
var r : TRect;
begin
  if Brush.Style <> bsClear then
    begin
    if Brush is TFPCustomDrawBrush then
      TFPCustomDrawBrush(Brush).Rectangle(0,0, width, height)
    else
      begin
      r := Rect(0,0, width, height);
      DoRectangleFill (r);
      end;
    end;
end;

but DoRectangleFill is some abstract method so I am still curious why I had to call Clear twice previously.

(Note that this demo project is simplificated and I maybe tried FillRect in my project but I am not sure now).
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Transparency issue
« Reply #3 on: August 30, 2011, 11:24:49 am »
Finally, I found the reason of my troubles.
The size of Canvas is lost after passing it through TMemoryStream (because of transparency).
Code: [Select]
//now Canvas.Width and Canvas.Height are set to some size
memStream:=TMemoryStream.Create;
try
  BMP.SaveToStream(memStream);
  memStream.Position:=0;
  BMP.LoadFromStream(memStream);
finally
  memStream.Free;
//now Canvas.Width and Canvas.Height are 0
But the size of Canvas is restored after some operation.
Therefore I had to do twice:
Code: [Select]
BMP.Canvas.Clear;
BMP.Canvas.Clear;
//OR
BMP.Canvas.FillRect(0, 0, BMP.Canvas.Width, BMP.Canvas.Height);
BMP.Canvas.FillRect(0, 0, BMP.Canvas.Width, BMP.Canvas.Height);
but this works immediately:
Code: [Select]
BMP.Canvas.FillRect(0, 0, BMP.Width, BMP.Height);
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018