首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从TImageList获取位图

从TImageList获取位图
EN

Stack Overflow用户
提问于 2012-11-13 06:18:53
回答 2查看 20.5K关注 0票数 4

我正在向图像列表中添加一个图像,就像这里- Add a png image to a imagelist in runtime using Delphi XE。从该列表中获取位图并将其保存到硬盘驱动器时出现问题。

代码语言:javascript
复制
bmp:=tbitmap.create;
imagelist.getbitmap(0,bmp);
bmp.savetofile()

这发生在许多白色的bmp文件和几个带有'image‘的文件中。这应该是非常容易的,但我不能理解哪里出了问题。

LE:这个例子更像是伪代码。代码如下:

填写列表

代码语言:javascript
复制
   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;

加载位图的问题

代码语言:javascript
复制
 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;

问题结束后编辑:请多投反对票!谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-13 06:39:26

如果你能给出一个不能工作的图像的例子,那肯定会有帮助。同时,您可以尝试使用以下代码:

代码语言:javascript
复制
bmp.PixelFormat := pf32bit;
bmp.AlphaFormat := afDefined;
ImageList.GetBitmap(0, bmp);
票数 5
EN

Stack Overflow用户

发布于 2012-11-13 16:02:21

基于Uwe Raabe's的回答,我将其设为work.Solution:

代码语言:javascript
复制
 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;

现在,位图已正确保存。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13352497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档