开发者

Delphi 6: TImage Width and Height properties report wrong values?

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 开发者_如何学Cit'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.


The TImage control is normally used to display image files (e.g. *.bmp files). Hence the control can load an image of any dimension, and then render it on the control's canvas using the specified properties (Center, Stretch, and Proportional). With that in mind, it is not that surprising that the width of the TImage control on the form differ from the size of the, well, Canvas, the Canvas of the associated bitmap, or whatever it might be.

If you do not load images, but rather want a control with a canvas to draw on, you should use TPaintBox. Or why not draw directly on the TForm?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜