ich möchte auf einer Form ein Hintergrundbild so platzieren, dass es passend „hereingezoomt“ wird – das Seitenverhältnis also nicht verändert wird, sondern stattdessen so lange gezoomt wird, bis die Form vollständig vom Bild ausgefüllt wird – ein Teil des Bildes ist dann abgeschnitten.
Dies löse ich mit einem TImage imgBackground, was entsprechend auf der Form frmPresent positioniert wird. imgBackground.Stretch, imgBackground.StretchInEnabled, sowie imgBackground.StretchOutEnabled sind alle auf true. Mit nachfolgender Positionierung kann ich mein gewünschtes Ergebnis erreichen:
Code: Alles auswählen
imgBackground.Width:=frmPresent.Width;
imgBackground.Height:=frmPresent.Height;
imgBackground.Picture.LoadFromFile(meinBild);
if imgBackground.Width/imgBackground.Height >= imgBackground.Picture.Width/imgBackground.Picture.Height then
begin
imgBackground.Height:=Trunc(imgBackground.Width*imgBackground.Picture.Height/imgBackground.Picture.Width);
imgBackground.Left:=0;
imgBackground.Top:=-Abs(Trunc((imgBackground.Height-frmPresent.Height)/2));
end
else
begin
imgBackground.Width:=Trunc(frmPresent.Height*imgBackground.Picture.Width/imgBackground.Picture.Height);
imgBackground.Left:=-Abs(Trunc((imgBackground.Width-frmPresent.Width)/2));
imgBackground.Top:=0;
end;
Hat jemand eine Idee, wie sich diese Zeit verkürzen lässt?
Vielen Dank schon mal!