Recent

Author Topic: drawing on timage canvas  (Read 574 times)

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
drawing on timage canvas
« on: June 25, 2022, 07:25:09 pm »
hi all ,
why timage color is always black even we change the color in the code to white


Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Math, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   StdCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     Image1: TImage;
  19.     ScrollBox1: TScrollBox;
  20.     procedure Button1Click(Sender: TObject);
  21.     procedure Button2Click(Sender: TObject);
  22.   private
  23.  
  24.   public
  25.  
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.Button1Click(Sender: TObject);
  38. var
  39.   xcenter, ycenter: longint;
  40.  
  41. begin
  42.   xcenter:=Image1.Width div 2;
  43.   ycenter:=Image1.Height div 2;
  44.   with Image1.Canvas do
  45.   begin
  46.          Brush.Color:=clWhite;
  47.          MoveTo(xcenter,ycenter);
  48.          Pen.Color:=clGreen;
  49.          LineTo(20,20);
  50.   end;
  51.  
  52. end;    
  53.  

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: drawing on timage canvas
« Reply #1 on: June 25, 2022, 07:47:01 pm »
Set the Picture property width, height ?

and you may need to draw on the picture property because the canvas is just the display surface and most likely will get covered.
The only true wisdom is knowing you know nothing

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: drawing on timage canvas
« Reply #2 on: June 25, 2022, 08:06:34 pm »
i found the solution

thanks
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   bm: TBitmap;
  4. begin
  5.   bm := TBitmap.Create;
  6.   with bm do
  7.   begin
  8.     bm.Width := Image1.Width;
  9.     bm.Height := Image1.Height;
  10.  
  11.     with Canvas do
  12.     begin
  13.       Brush.Color := clWhite;
  14.       FillRect(ClipRect);
  15.        Pen.Width := 3;
  16.       Pen.Color := clRed;
  17.       MoveTo(10, 10);
  18.       LineTo(190, 190);
  19.  
  20.     end;
  21.   end;
  22.        Image1.Picture.Bitmap := BM;
  23.   BM.Free;
  24. end;                              
  25.  
« Last Edit: June 25, 2022, 08:43:50 pm by alaa123456789 »

 

TinyPortal © 2005-2018