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
| // Chargement de l'image et ajout dans l'image list
Procedure TMainForm.DoOnFileFound(FileIterator : TFileIterator);
var
resizeBmp : TBitmap;
picture : TPicture;
fn:String;
Begin
Try
fn := FileIterator.Path+FileIterator.FileName;
if FileExistsUTF8(fn) then
begin
picture := TPicture.Create;
picture.LoadFromFile(fn);
resizeBmp := TBitmap.Create;
resizeBmp.Width := 64;
resizeBmp.Height := 64;
resizeBmp.Canvas.StretchDraw(Rect(0,0,63,63),picture.Bitmap);
imgList.AddMasked(resizeBmp,clDefault); // Ici le clDefault est important pour la bonne prise en charge de la transparence
End;
Finally
FreeAndNil(picture);
FreeAndNil(resizeBmp);
End;
End;
// Affichage
Procedure TMainForm.StringGrid1DrawCell(Sender : TObject; aCol, aRow : Integer; aRect : TRect; aState : TGridDrawState);
Var
imgIdx : Integer;
DstRect : TRect;
i,j : Integer;
Begin
if imgList.Count>0 then
begin
imgIdx := (aRow* TStringGrid(Sender).ColCount)+aCol;
if imgIdx < imgList.Count then
begin
DstRect := TStringGrid(Sender).CellRect(aCol,aRow);
imgList.Draw(TStringGrid(Sender).Canvas,DstRect.Left+2,DstRect.Top+2,imgIdx,dsTransparent,itImage,true);
End;
End;
end; |
Partager