加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi – 从TImageList获取位图

发布时间:2020-12-15 09:40:35 所属栏目:大数据 来源:网络整理
导读:我正在将图像添加到此处的图像列表中 – Add a png image to a imagelist in runtime using Delphi XE.从此列表中获取位图并将其保存到硬盘驱动器时会出现问题. bmp:=tbitmap.create;imagelist.getbitmap(0,bmp);bmp.savetofile() 这发生在很多白色bmp文件和
我正在将图像添加到此处的图像列表中 – 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;

问题结束后编辑:请更多downvotes!谢谢

解决方法

如果你能给出一些不起作用的图像的例子肯定会有所帮助.同时你可以尝试使用这段代码:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读