Advertisement
TLama

Untitled

Mar 1st, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.99 KB | None | 0 0
  1. unit Unit22;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     PaintBox1: TPaintBox;
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure FormDestroy(Sender: TObject);
  15.     procedure PaintBox1Paint(Sender: TObject);
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.     FBitmap: TBitmap;
  19.     procedure DrawSobel;
  20.     procedure DrawLabels;
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.dfm}
  31.  
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. begin
  34.   // create the draw buffer bitmap
  35.   FBitmap := TBitmap.Create;
  36. end;
  37.  
  38. procedure TForm1.FormDestroy(Sender: TObject);
  39. begin
  40.   // free the draw buffer bitmap
  41.   FBitmap.Free;
  42. end;
  43.  
  44. procedure TForm1.PaintBox1Paint(Sender: TObject);
  45. begin
  46.   // this event is fired when the system instructs the paint box control to repaint,
  47.   // so let's flush the prepared bitmap to the control's canvas here
  48.   PaintBox1.Canvas.Draw(0, 0, FBitmap);
  49. end;
  50.  
  51. procedure TForm1.DrawSobel;
  52. var
  53.   X, Y: Integer;
  54.   Row: PRGBTriple;
  55. begin
  56.   // modify the draw buffer bitmap size and draw what is needed on it
  57.   FBitmap.Width := Length(Img);
  58.   FBitmap.Height := Length(Img[0]);
  59.   for Y := 0 to FBitmap.Height - 1 do
  60.   begin
  61.     Row := FBitmap.ScanLine[Y];
  62.     // ...
  63.   end;
  64. end;
  65.  
  66. procedure TForm1.DrawLabels;
  67. var
  68.   I: Integer;
  69. begin
  70.   // and draw some labels to that same draw buffer bitmap
  71.   for I := 0 to High(obj_properties) do
  72.   begin
  73.     FBitmap.Canvas.Brush.Style := bsClear;
  74.     FBitmap.Canvas.MoveTo(50, 50);
  75.     FBitmap.Canvas.MoveTo(obj_properties[c].x+5, obj_properties[c].y+5);
  76.     // ...
  77.   end;
  78. end;
  79.  
  80. procedure TForm1.Button1Click(Sender: TObject);
  81. begin
  82.   // call methods for preparing draw buffer bitmap
  83.   DrawSobel;
  84.   DrawLabels;
  85.   // and tell the system we would like to repaint the paint box control
  86.   PaintBox1.Invalidate;
  87. end;
  88.  
  89. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement