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

将拉伸图像添加到Delphi中的ImageList

发布时间:2020-12-15 09:24:28 所属栏目:大数据 来源:网络整理
导读:我有一个表包含图片字段中的图像,我将把它们放入 ImageList. 这是代码: ImageList.Clear;ItemsDts.First;ImageBitmap:= TBitmap.Create;try while not ItemsDts.Eof do begin if not ItemsDtsPicture.IsNull then begin ItemsDtsPicture.SaveToFile(TempFil
我有一个表包含图片字段中的图像,我将把它们放入 ImageList.
这是代码:

ImageList.Clear;
ItemsDts.First;
ImageBitmap:= TBitmap.Create;
try
  while not ItemsDts.Eof do
  begin
    if not ItemsDtsPicture.IsNull then
    begin
      ItemsDtsPicture.SaveToFile(TempFileBitmap);
      ImageBitmap.LoadFromFile(TempFileBitmap);
      ImageList.Add(ImageBitmap,nil);
    end;
    ItemsDts.Next;
  end;
finally
  ImageBitmap.Free;
end;

但是我对ImageList大小不同的图像有一些问题.

更新:
我的问题是,当添加大于ImageList大小(32 * 32)的Image时,例如100 * 150它在连接到ImageList的组件中不能正确显示(例如在ListView中).
似乎新添加的图像没有被拉伸但是被克隆.我希望像ImageList编辑器一样拉伸新图像.

解决方法

我不知道ImageList是否提供了自动拉伸图像的属性.除非有人找到一些内置函数,否则您可以在将图像添加到ImageList之前自己展开图像.当你在它时,停止使用磁盘上的文件:改为使用TMemoryStream.像这样的东西:

var StretchedBMP: TBitmap;
    MS: TMemoryStream;

ImageList.Clear;
ItemsDts.First;
StretchedBMP := TBitmap.Create;
try

  // Prepare the stretched bmp's size
  StretchedBMP.Width := ImageList.Width;
  StretchedBMP.Height := ImageList.Height;

  // Prepare the memory stream
  MS := TMemoryStream.Create;
  try
    ImageBitmap:= TBitmap.Create;
    try
      while not ItemsDts.Eof do
      begin
        if not ItemsDtsPicture.IsNull then
        begin
          MS.Size := 0;
          ItemsDtsPicture.SaveToStream(MS);
          MS.Position := 0;
          ImageBitmap.LoadFromStream(MS);
          // Stretch the image
          StretchedBMP.Canvas.StretchDraw(Rect(0,StretchedBmp.Width-1,StretchedBmp.Height-1),ImageBitmap);
          ImageList.Add(StretchedBmp,nil);
        end;
        ItemsDts.Next;
      end;
    finally MS.Free;
    end;
  finally StretchedBMP.Free;
  end;
finally
  ImageBitmap.Free;
end;

PS:我在浏览器的窗口中编辑了你的代码.我不能保证它编译,但如果没有,它应该很容易修复.

(编辑:李大同)

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

    推荐文章
      热点阅读