TImage scanline not draws second time after drawing on Canvas lazarus / 39-Graphics ---------------------------------------------------------------------- Borneq · 2014-07-12 06:08 I have converted program from Delphi to Lazarus. In Delphi program works. In Lazarus - control TImage not redraw changes made by scanlines at second time after drawing on Canvas. I explain better: I attach source of my program At start it read samples.dat and fills list. If I click at "trójkąt" this draw black lines on white canvas, then I press "Piksele" (program IDE is in Polish, source in English) and OK - Draw Black/Yellow triangle Next I click "trójkat 2", it again draw on white canvas. Again I press "Piksele" and is ERROR: nothing I see. It should draw pixels again. In Delphi it is was OK. Maybe some resources not freed/bad initialized? ---------------------------------------------------------------------- howardpc · 2014-07-12 20:32 For FPC/Lazarus you need to wrap the Scanline call in BeginUpdate/EndUpdate calls thus: Code: [Select] uses graphics; ... procedure TForm1.InsideAllPoints(poly: TPoly); var ... begin ...     begin        BeginUpdate();        Line := Scanline[y];        EndUpdate();        for x := 0 to ...        ...     end; ---------------------------------------------------------------------- Borneq · 2014-07-12 22:41 Each scanline or block of scanlines? BeginUpdate/EndUpdate of which object? Image.Picture.Bitmap Very thanks! It Is helps! ---------------------------------------------------------------------- Borneq · 2014-07-13 06:31 Second question: If I choose "trojkat", method stay "simple", on left I choose "Detale" and press button "Piksele", then appear window "1227 punktów" If I change list positoin, it draw white small rectangle. There are two errors: - rectangle should be red - previous rectangle should be erased I draw rectangle in TDetailsForm.DrawPoint i unit Details.pas and erase in TDetailsForm.ErasePoint Before drawing I save rectangle to bitmap:   Bitmap.Canvas.CopyRect(Rect(0,0,DrawW,DrawH),Form1.Image.Canvas,R); If erase - I try restore from bitmap:   CopyRect(R, Bitmap.Canvas,Rect(0,0,DrawW,DrawH)); Restoring not works, and not works "Brush.Color:=clRed;" ---------------------------------------------------------------------- howardpc · 2014-07-14 10:06 I'm not exactly sure what DrawPoint/ErasePoint were trying to achieve, but try this. Change TDetailsform as follows: Code: [Select]   TDetailsForm = class(TForm)     lvPoints: TListView;     lvInsideSlopes: TListView;     lvOutsideSlopes: TListView;     btnOK: TButton;     Label1: TLabel;     Label2: TLabel;     procedure FormCreate(Sender: TObject);     procedure FormDestroy(Sender: TObject);     procedure lvPointsChange(Sender: TObject; Item: TListItem;       Change: TItemChange);   private     ErrPointList: TErrPointList;     FDrawPointNeeded: boolean;     FDrawPoint: TPoint;   public     procedure Clear;     procedure CollectErrorPoints(x,y: integer);     procedure Fill;     property DrawPointNeeded: boolean read FDrawPointNeeded write FDrawPointNeeded;     property DrawPoint: TPoint read FDrawPoint;   end;  and move to the public interface Code: [Select]const   DrawW=6; DrawH=6; change TDetailsForm.lvPointsChange as follows: Code: [Select]begin   if item.Selected=false then exit;   if lvPoints_lastSelected=item.Index then exit;   lvPoints_lastSelected:=item.Index;   ErrPoint:=Item.Data;   FDrawPointNeeded:=True;   FDrawPoint.x:=ErrPoint.x;   FDrawPoint.y:=ErrPoint.y;   Form1.Image.Refresh;   lvInsideSlopes.Clear;  ... etc. In DrawUnit add an OnPaint handler for the TImage, and code as follows: Code: [Select]procedure TForm1.ImagePaint(Sender: TObject); var   img: TImage;   procedure DrawPoint(aPt: TPoint);   var     r: TRect;   begin     r:=Rect(aPt.x-DrawW div 2,aPt.y-DrawH div 2,aPt.x+DrawW div 2,aPt.y+DrawH div 2);     img.Canvas.Brush.Color:=clRed;     img.Canvas.FillRect(r);   end; begin   img:=Sender as TImage;   if DetailsForm.DrawPointNeeded then begin     DrawPoint(DetailsForm.DrawPoint);     DetailsForm.DrawPointNeeded:=False;   end; end; You'll probably need to adapt all this to achieve exactly what you want, but it should give you an idea of how to interact with the paint process at the right moments. ---------------------------------------------------------------------- Borneq · 2014-07-14 12:07 Thanks, this works