How can I get the width and length of a Picture in a Timage Component in Delphi Firemonkey

109 views Asked by At

I'm using Delphi RAD Studio 11.3 with Firemonkey. When I place a TImage component on a form and load a picture into it, the bitmap is automatically resized to fit the TImage component. That's perfectly fine. What I'm trying to find out is how to obtain the width and height of the currently displayed image. I don't want the width and height of the TImage component itself (e.g., Image1.Width or Image1.Height), nor do I need the dimensions of the original image (e.g., Image1.Bitmap.Width or Image1.Bitmap.Height).

What I'm looking for is the width and height of the image as it's currently displayed on the TImage component. Having this information will allow me to calculate the X and Y coordinates based on a MouseMove event on the displayed image, and from there, I can derive the corresponding points on the underlying bitmap.

Any suggestions?

1

There are 1 answers

1
Tom Brunberg On BEST ANSWER

You need to calculate the extents of the visual area based on several properties. In addition to Position and Rotation (if applicable) of the TImage component, consider at least the following:

  1. The image size you have loaded into the TImage (might get stretched/shrunken to fit)
  2. WrapMode setting (default is Fit, which stretches/shrinks proprtionally)
  3. Size (or Width and Height seprately) of the TImage
  4. Scale (horizontally and vertcally separately) of the TImage