1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| function StretchBmp(Source, Dest: TBitmap; MaxWidth, MaxHeight: integer): boolean;
var
Scale: double;
NewHeight, NewWidth: Integer; // Ajoué
begin
Result:= false;
if (Source.Width = 0) or (Source.Height = 0) then Exit;
Scale:= Min(MaxWidth / Source.Width, MaxHeight / Source.Height); // il faut déclarer uses math
Dest.Width:= MaxWidth; // Ajoué
Dest.Height:= MaxHeight; // Ajoué
NewWidth:= Round(Source.Width * Scale); // Modifié
NewHeight:= Round(Source.Height * Scale); // Modifié
SetStretchBltMode(Dest.Canvas.Handle, HALFTONE);
Dest.Canvas.FillRect(Dest.Canvas.ClipRect);
Result:= StretchBlt(Dest.Canvas.Handle,
(MaxWidth-NewWidth) div 2, // Modifié
(MaxHeight-NewHeight) div 2, // Modifié
NewWidth, NewHeight,
Source.Canvas.Handle,
0, 0, Source.Width, Source.Height,
SRCCOPY);
end;
procedure FillListView(path: string; mask: string = '*.jpg');
var
sr: TSearchRec;
img: TPicture;
bmp: TBitmap;
pic: TBitMap;
begin
img := TPicture.Create;
bmp := TBitMap.Create;
pic := TBitMap.Create;
With Form1 do
if FindFirst(path + mask, $20, sr) = 0 then
begin
repeat
if (sr.Attr and $20) = $20 then
begin
try
img.LoadFromFile(path + sr.Name);
except
Continue;
end;
bmp.Assign(img.Graphic);
// pic.Width := 80;
// pic.Height:= 80;
// pic.Canvas.StretchDraw(Rect(0,0,pic.Width, pic.Height), bmp);
StretchBmp(Bmp, Pic, ImageList1.Width, ImageList1.Height); // Modifié
ImageList1.Add(Pic, nil);
with ListView1.Items.Add do begin
Caption := sr.Name;
ImageIndex := ListView1.Items.Count-1;
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
img.Free; bmp.Free; pic.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// ici tu ajustes la taille voulue ... Ex. 80
ImageList1.Width := 512; // Ajoué
ImageList1.Height := 512; // Ajoué
FillListView('C:\images\', '*.jpg');
FillListView('C:\images\', '*.bmp');
End; |
Partager