I have a TImage
on a resizable Form, and I want it to resize when I resize the Form.
What I tried:
- enabling all
Anchors
options - putting the
TImage
on aTPanel
, and then setting both Panel and Image alignments toalClient
- Assigning new
Width
andHeight
in the Form'sOnResize
event
None of these does the job.
This is the default Form size. The TImage
gets redrawn whenever any of the parameters on the left change, or if the image is zoomed in/out (using the mouse scroll wheel). On each redraw, the pattern repeats until it fills the full TImage
.
And this is the Form after resizing. Notice that the image size remains unchanged.
Enabling the Stretch
property does work, but it also scales the image's content, which I don't want.
How can I fix this?
I'm on Delphi 10.3
CodePudding user response:
Rereading your description, I see the problem.
When image dimensions change, inner picture doesn't change its size, if stretching is off. You have to modify inner bitmap size by hands:
Image2.Picture.Bitmap.Width := Image2.Width;
Image2.Picture.Bitmap.Height := Image2.Height;
//now diagonal is drawn properly
Image2.Canvas.MoveTo(0, 0);
Image2.Canvas.LineTo(Image2.Width, Image2.Height);