* * *

Author Topic: How to rotate image in Lazarus at any angle?  (Read 2728 times)

Stuckalf

  • Newbie
  • Posts: 4
How to rotate image in Lazarus at any angle?
« on: February 04, 2017, 12:25:00 am »
Hi all!

I'm just starting new with Pascal (after being absent for at least 10 years) and came across a problem I couldn't solve, yet:

How can I rotate an image (preferably png with transparent effects) at any angle between 0 and 359 degrees?
I need this for a fast rotation of two images, each of about 500 x 500 px size.

I installed the BGRABitmap library, but in lack of a complete documentation I couldn't get it to work.
Is it possible (on a computer with a modern i3 or i5) to rotate these images in realtime? 25 frames per second would be enough for me.

lainz

  • Hero Member
  • *****
  • Posts: 2082
Re: How to rotate image in Lazarus at any angle?
« Reply #1 on: February 04, 2017, 02:42:33 am »
Here it is attached rotate demo, notice that you need to install BGRAControls also to use this quick solution. It runs at 25 fps (every 40 ms updated). You can tweak this as you want.

Stuckalf

  • Newbie
  • Posts: 4
Re: How to rotate image in Lazarus at any angle?
« Reply #2 on: February 04, 2017, 11:06:41 am »
Thansk for the example.
It didn't compile on my system. The error message I get is:

bclistbox.pas(155,1) Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates.

-vd option didn't get more results to the error.

I installed BGRABitmap and BGRAControls with their *.lpk files.
Anything I did wrong?

Handoko

  • Hero Member
  • *****
  • Posts: 1781
  • My goal: build my own game engine using Lazarus
Re: How to rotate image in Lazarus at any angle?
« Reply #3 on: February 04, 2017, 01:02:42 pm »
As I don't use BGRABitmap, nothing much I can say about it.

But I know BGRABitmap has a good series of step-by-step tutorials, which can be very helpful for newbies:
http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial

lainz

  • Hero Member
  • *****
  • Posts: 2082
Re: How to rotate image in Lazarus at any angle?
« Reply #4 on: February 04, 2017, 02:09:27 pm »
Thansk for the example.
It didn't compile on my system. The error message I get is:

bclistbox.pas(155,1) Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates.

-vd option didn't get more results to the error.

I installed BGRABitmap and BGRAControls with their *.lpk files.
Anything I did wrong?

I don't know which version of Lazarus you're using and the OS?
Just open the package and remove bclistbox for now.

Stuckalf

  • Newbie
  • Posts: 4
Re: How to rotate image in Lazarus at any angle?
« Reply #5 on: February 04, 2017, 04:24:42 pm »
Ok. Interesting. The code compiles when I removed bclistbox from the package.
Thanks.
I've managed to put two of my objects onto the form and have them rotate at a descent speed.

But it seems the frame rate lowers if I switch the form to full size while running the animation.

lainz

  • Hero Member
  • *****
  • Posts: 2082
Re: How to rotate image in Lazarus at any angle?
« Reply #6 on: February 04, 2017, 04:29:19 pm »
Ok. Interesting. The code compiles when I removed bclistbox from the package.
Thanks.
I've managed to put two of my objects onto the form and have them rotate at a descent speed.

But it seems the frame rate lowers if I switch the form to full size while running the animation.

Yes this is software render, it doesn't uses the graphics card.

If you want OpenGL you need to install BGLControls.lpk and use, is different.

Stuckalf

  • Newbie
  • Posts: 4
Re: How to rotate image in Lazarus at any angle?
« Reply #7 on: February 04, 2017, 10:02:37 pm »
I tested the free Delphi 10 version. It comes with a property called "RotationAngle" for the TImage object.
Even on a moderate computer this gives quiet an impressive result.

For my project it seems I have to stick with Delphi. Although I'd prefer Lazarus.

Anyway thanks for your time and help.

lainz

  • Hero Member
  • *****
  • Posts: 2082
Re: How to rotate image in Lazarus at any angle?
« Reply #8 on: February 04, 2017, 10:34:24 pm »
I tested the free Delphi 10 version. It comes with a property called "RotationAngle" for the TImage object.
Even on a moderate computer this gives quiet an impressive result.

For my project it seems I have to stick with Delphi. Although I'd prefer Lazarus.

Anyway thanks for your time and help.

There's space always for optimization, like setting the width and height of the component only with the space you need.

Using BGLControls is also another good solution, faster because it uses OpenGL. But if with delphi works fine for you it's another way.
« Last Edit: February 04, 2017, 10:47:00 pm by lainz »

circular

  • Hero Member
  • *****
  • Posts: 2602
    • Personal webpage
Re: How to rotate image in Lazarus at any angle?
« Reply #9 on: February 07, 2017, 12:46:33 pm »
Indeed it would be fast with OpenGL.

Otherwise, the question was already asked some time ago:
http://forum.lazarus.freepascal.org/index.php/topic,17896.msg99866.html
Conscience is the debugger of the mind

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus