Transparency issue lazarus / 39-Graphics ---------------------------------------------------------------------- Blaazen · 2011-08-29 13:56 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. ---------------------------------------------------------------------- User137 · 2011-08-29 14:42 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 · 2011-08-29 15:01 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). ---------------------------------------------------------------------- Blaazen · 2011-08-30 09:24 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);