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
| procedure FillImageListFromResources(ImageList: TImageList; const BaseName: string; Count: Integer);
var
i: Integer;
bmp, tmp: TBitmap;
resName: string;
begin
if not Assigned(ImageList) then Exit;
ImageList.Clear;
for i := 1 to Count do
begin
resName := Format('%s%d', [BaseName, i]); // IMG1..IMG7
bmp := TBitmap.Create;
try
if LoadResourceToBitmap(resName, bmp) then
begin
if (ImageList.Width = 0) or (ImageList.Height = 0) then
begin
ImageList.Width := bmp.Width;
ImageList.Height := bmp.Height;
end;
if (bmp.Width <> ImageList.Width) or (bmp.Height <> ImageList.Height) then
begin
tmp := TBitmap.Create;
try
tmp.PixelFormat := pf24bit;
tmp.SetSize(ImageList.Width, ImageList.Height);
tmp.Canvas.Brush.Color := clWhite;
tmp.Canvas.FillRect(Rect(0, 0, tmp.Width, tmp.Height));
tmp.Canvas.StretchDraw(Rect(0, 0, tmp.Width, tmp.Height), bmp);
ImageList.Add(tmp, nil);
finally
tmp.Free;
end;
end
else
ImageList.Add(bmp, nil);
end
else
begin
// ressource manquante : ignorer ou ajouter placeholder
end;
finally
bmp.Free;
end;
end;
end; |
Partager