图片列表中的PNG图片 [英] PNG image from imagelist

查看:110
本文介绍了图片列表中的PNG图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从TImageList拍摄图片并将其放入TImage(或以TGraphic形式返回)?

How do I take a picture from a TImageList and put it into a TImage (or return it as a TGraphic)?

重要的一点是,TImageList可以包含32bpp的alpha混合图像.目标是获得这些alpha混合图像之一,并将其​​放置在TImage中.这意味着在某些时候我可能需要TGraphic.尽管严格来说,我的问题是将图像从 ImageList 放入 Image .如果没有中介TGraphic就能做到这一点,那也很好.

The important point is that a TImageList can contain 32-bpp alpha blended images. The goal is to get one of these alpha-blended images and place it in a TImage. This means at some point i would likely require a TGraphic. Although, strictly speaking, my question is about placing an image from an ImageList into an Image. If that can be accomplished without an intermedate TGraphic then that is also fine.

我们想要功能的胆量:

procedure GetImageListImageIntoImage(SourceImageList: TCustomImageList; 
      ImageIndex: Integer; TargetImage: TImage);
begin
   //TODO: Figure this out.
   //Neither SourceImageList.GetIcon nor SourceImageList.GetBitmap preserve the alpha channel
end;

还可以使用另一个有用的中间帮助器功能:

There can also be another useful intermediate helper function:

function ImageListGetGraphic(ImageList: TCustomImageList; ImageIndex: Integer): TGraphic;
var
//  ico: TIcon;
    bmp: TBitmap;
begin
    {Doesn't work; loses alpha channel. 
    Windows Icon format can support 32bpp alpha bitmaps. But it just doesn't work here
    ico := TIcon.Create;
    ImageList.GetIcon(ImageIndex, ico, dsTransparent, itImage);
    Result := ico;
    }

    {Doesn't work; loses alpha channel.
    Windows does support 32bpp alpha bitmaps. But it just doesn't work here
    bmp := TBitmap.Create;
    bmp.PixelFormat := pf32bit;
    Imagelist.GetBitmap(ImageIndex, bmp);
    Result := bmp;
    }
end;

让我们将原始过程转换为:

Letting us convert the original procedure to:

procedure GetImageListImageIntoImage(SourceImageList: TCustomImageList; ImageIndex: Integer; TargetImage: TImage);
var
   g: TGraphic;
begin
   g := ImageListGetGraphic(SourceImageList, ImageIndex);
   TargetImage.Picture.Graphic := g; //Assignment of TGraphic does a copy
   g.Free;
end;

我也有一些随机的事情:

I also some random things:

Image1.Picture := TPicture(ImageList1.Components[0]);

但是不会编译.

P.S.我有Delphi 2010

P.S. I have Delphi 2010

推荐答案

ImageList1.GetBitmap(0, Image1.Picture.Bitmap);

这篇关于图片列表中的PNG图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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