【发布时间】:2012-11-12 22:18:53
【问题描述】:
我正在将图像添加到像这里这样的图像列表 - Add a png image to a imagelist in runtime using Delphi XE。从此列表中获取位图并将其保存到硬盘驱动器时会出现问题。
bmp:=tbitmap.create;
imagelist.getbitmap(0,bmp);
bmp.savetofile()
这发生在很多白色 bmp 文件和一些带有“图像”的文件中。它应该非常容易,但我不明白出了什么问题。
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;
问题结束后编辑:请多投反对票!谢谢
【问题讨论】:
-
可能是我,但我找不到你提到问题的地方。
-
好吧,SaveToFile 的文件名会很好。
-
请贴出真实代码;这不会编译,因为没有文件名就没有
TBitmap.SaveToFile。你也没有真正问过问题。 -
因什么原因关闭?对问题进行了编辑以呈现整个问题。
-
@RBA - 有时编辑问题为时已晚,一旦票数接近,人们可能会继续投票而无需进行广泛检查。顺便说一句,恕我直言,目前您的编辑并没有使问题很明显,问题在代码 sn-p 的注释中说明,并且必须滚动才能看到它(创建位图,但它是白色的)。