I'm having a fairly strange problem with a TImage component's width and height properties. As a test, I draw a red dot in (what is supposed to be) the center of the TImage component by taking the midpoint of the TImage's width and height and drawing the dot there so that it is centered (centerPoint2D is a TPoint):
// The center point is the center of the display area.
centerPoint2D.X := Trunc(Image1.Width / 2);
centerPoint2D.Y := Trunc(Image1.Height / 2);
Image1.Canvas.Brush.Color := clRed;
Image1.Canvas.Brush.Style := bsSolid;
Image1.Canvas.Ellipse(centerPoint2D.X - 5, centerPoint2D.Y - 5, centerPoint2D.X + 5, centerPoint2D.Y + 5);
The red dot does not appear in the center of the TImage but somewhere well below and to the right to it. In addition, any text I print to the component appears stretched. It's as if the TImage is much larger than the reported dimensions, larger than what is visible from the apparent viewport, as if what is visible is clipped.
Additional Details. The TImage control sits on a TPanel that sits on a TGroupBox that sits on the TFrame. However, all of those components have their Align property set to alClient. The TFrame itself has it's Align property set to alNone. However, the instance of it that sits on the Form has it's Align property set to alClient at design time. In other words, it should not be a case of the TImage component being larger than the portion of it that is visible at runtime. In addition, the dimensions reported do appear to match the size of the component as it appears on screen to my eye, but I do not have "pixel ruler" utility to confirm that objectively.
Image1.Width div 2
is faster thantrunc(Image1.Width / 2)
. – Andreas Rejbrand