Steve F
Steve F

Reputation: 1577

How to get top position of TImage picture?

I have a TImage with Align := alClient, Stretch := True, Proportional := True and Center := True inside a TPanel. How to get the top pixel position of the picture that is drawn in the image?

Perhaps an image describing the problem will help: enter image description here

I saw this question, but could not get the answer for what I need which is closely related.

Upvotes: 2

Views: 1688

Answers (1)

Andreas Rejbrand
Andreas Rejbrand

Reputation: 109002

There will only be space left at the top and bottom if the aspect ratio of the image is greater than that of the panel. Assuming this is the case, the desired distance is

round(Panel.Height - (Panel.Width / Image.Picture.Width) * Image.Picture.Height) / 2);

Upvotes: 3

Related Questions