我正在像這裏添加圖像到圖像列表 - Add a png image to a imagelist in runtime using Delphi XE。從列表中獲取位圖並將其保存到硬盤驅動器時出現問題。Delphi - 從TImageList獲取位圖
bmp:=tbitmap.create;
imagelist.getbitmap(0,bmp);
bmp.savetofile()
這發生在很多白色bmp文件和幾個'圖像'。它應該是非常容易的,但我不明白什麼是錯的。
LE:這個例子是多爲僞code.code波紋管:
填充列表
FImageList := TImageList.Create(nil);
FImageList.Masked:=false;
FImageList.ColorDepth:=cd32bit;
FImageList.SetSize(32,32);//I am sure that all images are 32x32
while not dsTemp.eof do//dstemp is a Tdatasetdescendant
begin
ststream := dsTemp.CreateBlobStream(dsTemp.FieldByName('FLAG'), bmRead);
pngImage := TPngImage.Create;
pngImage.LoadFromStream(ststream);
btBitmap := TBitmap.Create;
btBitmap.PixelFormat := pf32bit;
btBitmap.Width := pngImage.Width ;
btBitmap.Height := pngImage.Height ;
pngImage.AssignTo(btBitmap);
btBitmap.AlphaFormat:=afIgnored;
res := FImageList.Add(btBitmap,nil);
// pngImage.savetofile('C:\a\'+inttostr(res)+'.png');-works. image is ok
// btBitmap.savetofile('C:\a\'+inttostr(res)+'.bmp');-works. image is ok
dsTemp.Next;
freeandnil(btBitmap);
freeandnil(pngImage);
end;
與加載位圖的問題是
for iPos := 0 to FImageList.Count-1 do
begin
btBitmap := tbitmap.create;
FImageList.GetBitmap(iPos,btBitmap);
btBitmap.savetofile('C:\a\'+inttostr(iPos)+'thr.bmp');//creates the bitmap, but it is white
end;
編輯後的問題關閉:請更多downvotes!謝謝
也許這是我,但我找不到你提到*問題*的地方。 –
好了,SaveToFile的文件名會很好。 –
請發佈實際代碼;這將不會編譯,因爲沒有'TBitmap.SaveToFile'沒有文件名。你也沒有真正問過一個問題。 –