가장 간단한 방법은 다른 그래픽 형식의로드가 이미 구현되어 있고 다른 이미지 클래스를주의해야하기 때문에 TPicture를 사용하는 것입니다.
필수 단위가 with와 같이 여기에 포함되도록해야합니다. jpeg, gifimg 및 pngimg.
TPicture.LoadFromFile을로드 한 후 Imagelist의 크기가있는 준비된 Bitmap에 이미지가 그려지며 가운데 맞춤 및 크기 조절됩니다.
마지막 단계는 비트 맵으로 teh AddBitmap 프로 시저를 호출하고 마스크에 대해 nil을 호출하는 것입니다.
// make sure you included the needed units
// uses pngImage,jpeg,gifimg;
Procedure LoadImagesFromDataset2ImageList(il: TImageList; DS: TDataset; const FileFieldname: String);
var
P: TPicture;
bmp: TBitmap;
Function CalcRectAndPrepare: TRect; // calculate Rect for here centered/streched output
var // and fill the bitmap with the desired beckground color
f: Double;
begin
bmp.Canvas.Brush.Color := clWhite;
bmp.Canvas.FillRect(Rect(0, 0, bmp.Width, bmp.Height));
if P.Width > P.Height then
f := bmp.Width/P.Width
else
f := bmp.Height/P.Height;
Result.Left := Round(bmp.Width - P.Width * f) div 2;
Result.Top := Round(bmp.Height - P.Height * f) div 2;
Result.Right := bmp.Width - Result.Left;
Result.Bottom := bmp.Height - Result.Top;
end;
begin
P := TPicture.Create;
bmp := TBitmap.Create;
try
bmp.Width := il.Width;
bmp.Height := il.Height;
DS.First;
while not DS.Eof do
begin
if FileExists(DS.Fieldbyname(FileFieldname).asString) then
begin
P.LoadFromFile(DS.Fieldbyname(FileFieldname).asString);
bmp.Canvas.StretchDraw(CalcRectAndPrepare, P.Graphic);
il.Add(bmp, nil);
end;
DS.Next;
end;
finally
P.Free;
bmp.Free;
end;
end;
어떤 부분이 당신을 위해 문제를 해결합니까? 파일을 TPicture에로드 하시겠습니까? 비트 맵을 imagelist에 추가 하시겠습니까? imagelist와 Dataset/Listview/Listbox 사이를 추적하고 있습니까? – bummi
@bummi 위의 모든 것, 슬프게도. –
@bummi 사실 당신의 의견은 제 질문에 거의 답합니다. 그래서 나는 TPicture를 인스턴스화하고, 파일에서로드하고, imagelist에 추가하고 모든 세부 테이블 레코드에 대해 반복해야한다고 생각합니다. 답변으로 의견을 넓힐 수 있다면 기꺼이 받아 들일 것입니다. –