Voici le code en cet instant :
Cela ne semble pas fonctionner, j'ai du aller trop vite dans la transposition...
Procedure Stretch(aImage : TImage; sPath : String; lMaxWidth, lMaxHeight : LongInt);
Var
lOldWidth,
lOldHeight,
lNewWidth,
lNewHeight : LongInt;
cRatio : Real;
oStd : TBitmap;
begin
{régule la taille MAX par défaut}
If (lMaxWidth <= 0) Or (lMaxWidth > aImage.Width) Then lMaxWidth := aImage.Width;
If (lMaxHeight <= 0) Or (lMaxHeight > aImage.Height) Then lMaxHeight := aImage.Height;
{charge l'image et récupère sa taille}
oStd := TBitMap.Create;
with oStd do
begin
LoadFromFile(sPath);
lOldWidth := oStd.Width;
lOldHeight := oStd.Height;
{orientation, on va étirer l'image au plus possible en touchant la taille
max autorisée avec le bord du type d'image.
l'autre côté peut tout de même dépasser}
If lOldWidth > lOldHeight Then
begin
{image réelle : paysage}
lNewWidth := lMaxWidth;
cRatio := lMaxWidth / lOldWidth;
lNewHeight := Round(lOldHeight * cRatio);
If lNewHeight > lMaxHeight Then
begin
{la hauteur dépasse, même manip}
cRatio := lMaxHeight / lNewHeight;
lNewHeight := lMaxHeight;
lNewWidth := round(lNewWidth * cRatio);
end;
end else
begin
{image réelle : portrait}
lNewHeight := lMaxHeight;
cRatio := lMaxHeight / lOldHeight;
lNewWidth := Round(lOldWidth * cRatio);
If lNewWidth > lMaxWidth Then
begin
{la largeur dépasse, même manip}
cRatio := lMaxWidth / lNewWidth;
lNewWidth := lMaxWidth;
lNewHeight := round(lNewHeight * cRatio);
end;
End;
end;
{on dessine le rendu centré (NB : l'API StretchBlt donne une trop mauvaise
qualité, autant passer par la méthode accessible par le contrôle)}
aImage.Picture.Assign(oStd);
oStd.Free;
End;
procedure TForm1.FormPaint(Sender: TObject);
begin
Stretch(Image1,ExtractFilePath(application.ExeName)+'\Croix1.bmp',
Image1.Width div 2, Image1.Height div 2);
end;
Merci pour vos remarques!
Jean_Jean