Recent

Author Topic: How to Rotate a TImage Programmatically in Lazarus IDE?  (Read 2764 times)

Aruna

  • Hero Member
  • *****
  • Posts: 787
Re: How to Rotate a TImage Programmatically in Lazarus IDE?
« Reply #15 on: March 30, 2025, 12:47:38 pm »
If you want a procedure that can rotate the Bitmap of a TImage by 90/180/270° then have a look at reply #6 in https://forum.lazarus.freepascal.org/index.php/topic,69327.0.html where you can find a nice solution by wp.
Thank you @Hartmut.

Aruna

  • Hero Member
  • *****
  • Posts: 787
Re: How to Rotate a TImage Programmatically in Lazarus IDE?
« Reply #16 on: March 30, 2025, 12:48:21 pm »
LS,
have a look at Marek Mauder's 'Vampyre Imaging Library' which has ready-made functions in file Imaging.pas to rotate or mirror an image.

https://github.com/galfar/imaginglib
@Arend041 thank you for sharing.

Aruna

  • Hero Member
  • *****
  • Posts: 787
Re: How to Rotate a TImage Programmatically in Lazarus IDE?
« Reply #17 on: March 30, 2025, 12:49:17 pm »
Here is another example that rotates by 90/180/270°, but also by any angle.
When rotating by any angle, the image content is interpolated.
And the transparency is retained.

The core of the whole thing is the unit rhsBitmapRotate.pas, which I have built into the enclosed test program.
@Ally, thank you.

Aruna

  • Hero Member
  • *****
  • Posts: 787
Re: How to Rotate a TImage Programmatically in Lazarus IDE?
« Reply #18 on: March 30, 2025, 01:27:31 pm »
There's one example on the wiki
https://wiki.freepascal.org/fcl-image#Rotating_a_bitmap_image_by_an_arbitrary_angle

It's for fcl-image, still can easily be adapted to LCL though.
@Nimbus thank you very much. This looks very interesting. I think I will go with this and write my own. I will keep everyone posted.

Aruna

  • Hero Member
  • *****
  • Posts: 787
Re: How to Rotate a TImage Programmatically in Lazarus IDE?
« Reply #19 on: March 31, 2025, 04:50:35 am »
Hello Everyone,

I am sharing my first attempt at rotating an image using FPImage. It took a while to figure things out and now we have 90/180/270/360-degree clockwise rotation. A big thank you to everyone who offered advice shared helpful links, and provided support along the way — every bit truly made a difference. YOu can load a image, rotate then save to a file.

I have attached a zip file containing the full source code. I hope you enjoy using this as much as I did putting it together!

Aruna

 

TinyPortal © 2005-2018