我正在向图像列表中添加一个图像,就像这里- Add a png image to a imagelist in runtime using Delphi XE。从该列表中获取位图并将其保存到硬盘驱动器时出现问题。
bmp:=tbitmap.create;
imagelist.getbitmap(0,bmp);
bmp.savetofile()这发生在许多白色的bmp文件和几个带有'image‘的文件中。这应该是非常容易的,但我不能理解哪里出了问题。
LE:这个例子更像是伪代码。代码如下:
填写列表
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;问题结束后编辑:请多投反对票!谢谢
发布于 2012-11-13 06:39:26
如果你能给出一个不能工作的图像的例子,那肯定会有帮助。同时,您可以尝试使用以下代码:
bmp.PixelFormat := pf32bit;
bmp.AlphaFormat := afDefined;
ImageList.GetBitmap(0, bmp);发布于 2012-11-13 16:02:21
基于Uwe Raabe's的回答,我将其设为work.Solution:
for iPos := 0 to FImageList.Count-1 do
begin
btBitmap := tbitmap.create;
btBitmap.PixelFormat := pf32bit;
btBitmap.AlphaFormat := afIgnored;
FImageList.GetBitmap(iPos,btBitmap);
btBitmap.savetofile('C:\a\'+inttostr(iPos)+'thr.bmp');
end;现在,位图已正确保存。
https://stackoverflow.com/questions/13352497
复制相似问题