Description of the AutoSize property:
"Allows to automatically adjust the size of the control, according to its content."
This should IMHO mean, that a TImage assumes the size of the image drawn on screen.
What it actually does, seems to be a mix - the height is set according to constraints, image scaled to fit, and width is set to the original, and not the scaled image.
Constraints: "The minimal and maximal Width and Height of this control."
Not setting AutoSize to true, makes the width of the TImage a default size - the size a TImage gets, if it is just dropped at designtime, if it is not limited by the constraint width.
I tried setting a smaller width - but that apparently overwrites Constraints!
Changed programming, so scaling is done manually.
Image created like this:
constructor TPlayImage.Create(aInfo:TPlayInfo; aHeight:integer);
begin
inherited Create(aInfo);
Parent := aInfo;
FCont := AInfo.FCont;
Color := clNone;
Width := aHeight;
Height := aHeight;
Name := 'Image_'+IntToStr(aInfo.FIndex);
StretchInEnabled := true;
Proportional := true;
AnchorSide[akLeft].Side := asrLeft;
AnchorSide[akLeft].Control := aInfo;
AnchorSide[akTop].Side := asrCenter;
AnchorSide[akTop].Control := aInfo;
BorderSpacing.Left := 4;
BorderSpacing.Around := 1;
Anchors := [akLeft, akTop];
DragMode := dmManual;
DragKind := dkDrag;
end;
Then loading and scaling the image like this
procedure TPlayInfo.SetInfo(aImg, aTxt:string);
var
fWidth, fHeight : integer;
psc, hsc : real;
begin
FImage.Picture.LoadFromFile(aImg);
fWidth := FImage.Picture.Bitmap.Width;
fHeight := FImage.Picture.Bitmap.Height;
psc := FMaxImgSize/fWidth;
hsc := FMaxImgSize/fHeight;
if (psc > hsc) then psc := hsc;
if psc > 1 then psc := 1;
fWidth := round(fWidth*psc); // Billeddimension i pixels
fHeight := round(fHeight*psc);
FImage.Width := fWidth; // Billeddimension i pixels
FImage.Height := fHeight;
FInfoLabel.Caption := aTxt;
Refresh;
end;
It may not be optimal - but in contrast to what would be logical (from documentation) this has the advantage, of actually producing the desired results.