Bonjour,
Existe t-il un moyen de centrer verticalement les images dans une stringgrid ? Si oui je n'ai pas trouvé le truc et les images sont collées en haut ( Voir image jointe ).
Si c'est impossible par programmation une alternative consisterai à les entourer d'un cadre au dimensions des cellules mais je ne sais comment faire.
Ci-dessous le code utilisé:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 { ---- Creation de vignette ---- } Procedure TForm1.CreateThumb(Filename:String; NbTh, NbCur:Integer); Var Img_Picture: TPicture; Thumbnail: TJPEGImage; H_Max, W_Max:Integer; Scale:Double; Dir_Thumbs, Th_Name:String; begin Img_Picture := TPicture.Create; Thumbnail := TJPEGImage.Create; W_Max:=100; H_Max:=100; Scale:=1; Th_Name:=Set_ThName(Filename); Dir_Thumbs:=ExtractFilePath(Filename)+'/thumbs'; If not FileExists(Dir_Thumbs) then mkdir(Dir_Thumbs); If FileExists(Th_Name) then exit; L_Thumb.Caption:='génération de la vignette: '+IntToStr(NbCur)+' / '+IntToStr(NbTh); Application.ProcessMessages; try Img_Picture.LoadFromFile(Filename); Thumbnail.Assign(Img_Picture.Graphic); If Thumbnail.Width>Thumbnail.Height then begin If ThumbNail.Width>W_Max then begin Scale:=Thumbnail.Width/W_Max; end; end else begin if Thumbnail.Height>H_Max then begin Scale:=Thumbnail.Height/H_Max; end; end; Thumbnail.Width:=Thumbnail.Width div round(Scale); Thumbnail.Height:=Thumbnail.Height div round(Scale); ThumbNail.Canvas.StretchDraw(Rect(0, 0, Thumbnail.Width, Thumbnail.Height), Img_Picture.Graphic); Thumbnail.SaveToFile(Th_Name); finally Img_Picture.Free; Thumbnail.Free; end; End;PS: J'ai viré stretchdraw. Ca remplit bien les cellules mais déforme l'image de manière déplaisante.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 { ---- Remplir les cellules de la grille avec les images ----} procedure TForm1.G_Img_ListDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState); Var CurrImg:TImage; begin if (sender as Tstringgrid).Objects[Acol,Arow] = nil then Exit; CurrImg := TImage((sender as Tstringgrid).Objects[Acol,Arow]); // (sender as Tstringgrid).Canvas.StretchDraw( aRect, CurrImg.Picture.Graphic); (sender as Tstringgrid).Canvas.Draw( aRect.Left,aRect.Top, CurrImg.Picture.Graphic); end;
Merci.
Partager