Delphi-从TImageList获取位图 [英] Delphi - get bitmap from a TImageList

查看:438
本文介绍了Delphi-从TImageList获取位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图像添加到此处的图像列表-在运行时使用Delphi XE将png图像添加到图像列表中。从此列表中获取位图并将其保存到硬盘驱动器时,会出现问题。

I'm adding an image to an imagelist like here - Add a png image to a imagelist in runtime using Delphi XE. The problem occurs when getting an bitmap from this list and saving it to the hard drive.

bmp:=tbitmap.create;
imagelist.getbitmap(0,bmp);
bmp.savetofile()

这种情况出现在很多白色bmp文件中,有些带有'图片'。

this occurs in a lot of white bmp files and several with 'image'. it should be extremely easily but I can not understand what is wrong.

LE:示例更多是伪代码。下面是

LE: the example was more as pseudo-code.code bellow:

填充列表

   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;

在问题关闭后编辑:请更多投票!谢谢

Edit after the question was closed: more downvotes please! Thanks

推荐答案

如果您能为无法使用的图片举例,肯定会有所帮助。同时,您可以尝试使用以下代码:

It would definitely help if you could give an example for the images that dont't work. Meanwhile you can try playing around with this code:

bmp.PixelFormat := pf32bit;
bmp.AlphaFormat := afDefined;
ImageList.GetBitmap(0, bmp);

这篇关于Delphi-从TImageList获取位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆