から写真を撮ってTImageList
に入れるTImage
(または として返すTGraphic
) にはどうすればよいですか?
重要な点は、aTImageList
には 32 bpp のアルファ ブレンド画像を含めることができるということです。目標は、これらのアルファ ブレンド画像の 1 つを取得し、TImage
. これは、ある時点でTGraphic
. ただし、厳密に言えば、私の質問はImageListからImageに画像を配置することです。それが中間者なしで達成できれば、それTGraphic
も問題ありません。
私達何が欲しいの?
関数の内臓が必要です。
procedure GetImageListImageIntoImage(SourceImageList: TCustomImageList;
ImageIndex: Integer; TargetImage: TImage);
begin
//TODO: Figure this out.
//Neither SourceImageList.GetIcon nor SourceImageList.GetBitmap preserve the alpha channel
end;
別の便利な中間ヘルパー関数もあります。
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;
元の手順を次のように変換します。
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;
私もいくつかのランダムなもの:
Image1.Picture := TPicture(ImageList1.Components[0]);
しかし、それはコンパイルされません。
PS私はDelphi 2010を持っています