unit Unit22; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Button1: TButton; PaintBox1: TPaintBox; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure PaintBox1Paint(Sender: TObject); procedure Button1Click(Sender: TObject); private FBitmap: TBitmap; procedure DrawSobel; procedure DrawLabels; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin // create the draw buffer bitmap FBitmap := TBitmap.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin // free the draw buffer bitmap FBitmap.Free; end; procedure TForm1.PaintBox1Paint(Sender: TObject); begin // this event is fired when the system instructs the paint box control to repaint, // so let's flush the prepared bitmap to the control's canvas here PaintBox1.Canvas.Draw(0, 0, FBitmap); end; procedure TForm1.DrawSobel; var X, Y: Integer; Row: PRGBTriple; begin // modify the draw buffer bitmap size and draw what is needed on it FBitmap.Width := Length(Img); FBitmap.Height := Length(Img[0]); for Y := 0 to FBitmap.Height - 1 do begin Row := FBitmap.ScanLine[Y]; // ... end; end; procedure TForm1.DrawLabels; var I: Integer; begin // and draw some labels to that same draw buffer bitmap for I := 0 to High(obj_properties) do begin FBitmap.Canvas.Brush.Style := bsClear; FBitmap.Canvas.MoveTo(50, 50); FBitmap.Canvas.MoveTo(obj_properties[c].x+5, obj_properties[c].y+5); // ... end; end; procedure TForm1.Button1Click(Sender: TObject); begin // call methods for preparing draw buffer bitmap DrawSobel; DrawLabels; // and tell the system we would like to repaint the paint box control PaintBox1.Invalidate; end; end.