1
Graphics / Re: Drawing grid lines on a transparent image
« Last post by KodeZwerg on Today at 05:42:19 pm »Here an example:
(I have assigned in designer an image to the TImage control.)
If you can follow my code, FBMP keeps the original unmodified version of your image, the checkbox control if there are gridlines drawn over or if it replace current with original.
(I have assigned in designer an image to the TImage control.)
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
- type
- { TForm1 }
- TForm1 = class(TForm)
- CheckBox1: TCheckBox;
- Image1: TImage;
- Panel1: TPanel;
- procedure CheckBox1Change(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- strict private
- FBMP: TBitmap;
- private
- public
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FBMP := TBitmap.Create;
- FBMP.Assign(Image1.Picture.Bitmap);
- end;
- procedure TForm1.CheckBox1Change(Sender: TObject);
- var
- i: Integer;
- GridSize: Integer;
- LBMP: TBitmap;
- X, Y: Integer;
- begin
- GridSize := 50;
- LBMP := TBitmap.Create;
- try
- LBMP.PixelFormat := pf32bit;
- LBMP.Width := Image1.ClientRect.Width;
- LBMP.Height := Image1.ClientRect.Height;
- if CheckBox1.Checked then
- begin
- X := 0;
- Y := 0;
- LBMP.Assign(Image1.Picture.Bitmap);
- LBMP.Canvas.Brush.Color := clBlack;
- LBMP.Canvas.Brush.Style := bsSolid;
- for i := 0 to GridSize do
- if ((X + GridSize) < LBMP.Width) then
- begin
- Inc(X, GridSize);
- LBMP.Canvas.FillRect(X, LBMP.Canvas.ClipRect.Top, Succ(X), LBMP.Canvas.ClipRect.Bottom);
- end;
- for i := 0 to GridSize do
- if ((Y + GridSize) < LBMP.Height) then
- begin
- Inc(Y, GridSize);
- LBMP.Canvas.FillRect(LBMP.Canvas.ClipRect.Left, Y, LBMP.Canvas.ClipRect.Right, Succ(Y));
- end;
- end
- else
- LBMP.Assign(FBMP);
- Image1.Picture.Bitmap.Assign(LBMP);
- finally
- LBMP.Free;
- end;
- end;
- end.