Recent

Author Topic: [SOLVED] drawing a grid on a TImage  (Read 728 times)

petevick

  • Sr. Member
  • ****
  • Posts: 421
[SOLVED] drawing a grid on a TImage
« on: April 03, 2023, 10:39:41 am »
I'm attempting to import a project written in RapidQ to Lazarus. Part of the project draws different sized grids on a TImage. In RapidQ the QImage accepts Double variables so if the QImage size is 350x350 and a grid of 55x55 is drawn on it, then the space between the grid lines is 350 / 55 which equals 6.3636 etc, but in Lazarus the TImage.Canvas.Line() only accepts LongInt variables. I really can't see any way around it.
« Last Edit: April 03, 2023, 06:25:20 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

balazsszekely

  • Guest
Re: drawing a grid on a TImage
« Reply #1 on: April 03, 2023, 11:38:26 am »
I'm attempting to import a project written in RapidQ to Lazarus. Part of the project draws different sized grids on a TImage. In RapidQ the QImage accepts Double variables so if the QImage size is 350x350 and a grid of 55x55 is drawn on it, then the space between the grid lines is 350 / 55 which equals 6.3636 etc, but in Lazarus the TImage.Canvas.Line() only accepts LongInt variables. I really can't see any way around it.
I would create a transparent 3500x3500 bgrabitmap, draw the grid at 64(close enough), resize the image back to 350x350, then draw the grid to the original image with transparency. You can also play with the tickness of the pen.
IIRC bgrabitmap supports anti-aliasing lines too.
« Last Edit: April 03, 2023, 11:56:39 am by GetMem »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: drawing a grid on a TImage
« Reply #2 on: April 03, 2023, 11:43:04 am »
Or if you don't want to do the resizing you can just

Code: Pascal  [Select][+][-]
  1. const
  2.   Lines = 55;
  3. for I := 1 to Lines-1 do
  4.   Image1.Canvas.Line(Round(Single(I) * Image1.Width / Lines), 0, Round(Single(I) * Image1.Width / Lines), Image.Height);
« Last Edit: April 03, 2023, 11:44:56 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

petevick

  • Sr. Member
  • ****
  • Posts: 421
Re: drawing a grid on a TImage
« Reply #3 on: April 03, 2023, 12:24:04 pm »
Or if you don't want to do the resizing you can just

Code: Pascal  [Select][+][-]
  1. const
  2.   Lines = 55;
  3. for I := 1 to Lines-1 do
  4.   Image1.Canvas.Line(Round(Single(I) * Image1.Width / Lines), 0, Round(Single(I) * Image1.Width / Lines), Image.Height);
Well I'll be damned, that's spot on, I would never have got that. Thanks for posting Eugene, and GetMem  ;D
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

 

TinyPortal © 2005-2018