微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

图像列表中的PNG图像

我如何从timageList拍摄图片并将其放入timage (或将其作为TGraphic返回)?

重要的一点是timageList可以包含32-bpp alpha混合图像。 目标是获得这些alpha混合的图像之一,并将其​​放置在timage 。 这意味着在某些时候我可能会需要一个TGraphic 。 虽然,严格来说,我的问题是关于将ImageList中图像放入Image中 。 如果这可以完成没有intermedate TGraphic那么这也是好的。

我们想要什么?

我们需要一个function的胆量:

procedure GetimageListimageIntoImage(SourceImageList: TCustomImageList; ImageIndex: Integer; Targetimage: timage); begin //Todo: figure this out. //Neither SourceImageList.GetIcon nor SourceImageList.GetBitmap preserve the alpha channel end;

还可以有另一个有用的中间帮助函数

使用命令行打开Windows计划任务Gui属性

为什么模拟鼠标单击(使用mouse_event)只能在选定的组件上工作?

Delphi:系统菜单是否打开?

媒体播放器作为Windows服务

delphi的GDI行距?

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

udp丢包

如何访问Windowsshell上下文菜单项?

使用访问令牌共享进程pipe理权限

如何在Delphi中枚举另一个进程的窗口?

delphi – 系统托盘图标不打开应用程序备份

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

常规从ImageList中获取透明图形:

function ImageListGetGraphic(ImageList: TCustomImageList; ImageIndex: Integer): TGraphic; var ico: HICON; // png: TPngImage; // icon: TIcon; // bmp: TBitmap; wicbmp: IWICBitmap; wi: TWicImage; begin { //Works. Uses our own better Wic library. ico := ImageList_GetIcon(ImageList.Handle,ImageIndex,ILD_norMAL); Result := TWicGraphic.FromHICON(ico); DestroyIcon(ico);} //Works,uses the built-in Delphi TWicImage (careful of VCL bugs) ico := ImageList_GetIcon(ImageList.Handle,ILD_norMAL); wi := TWICImage.Create; //Due to a bug in the VCL,you must construct the TWicImage before trying to access the Wic ImagingFactory OleCheck(TWicImage.ImagingFactory.CreateBitmapFromHICON(ico,wicbmp)); wi.Handle := wicbmp; Result := wi; { //Doesn't work,loses alpha channel icon := TIcon.Create; ImageList.GetIcon(ImageIndex,icon,itimage); Result := icon; } { //Doesn't work,loses alpha channel bmp := TBitmap.Create; bmp.PixelFormat := pf32bit; Imagelist.GetBitmap(ImageIndex,bmp); Result := bmp; } { //Fails: cannot assign a TIcon to a TPngImage icon := TIcon.Create; ImageList.GetIcon(ImageIndex,ImgList.dsnormal,itimage); png := TPngImage.Create; png.Assign(icon); Result := png; icon.Free; } { //Working failure; doesn't support stretched drawing (eg timage.Stretch = true) icon := TIcon.Create; ImageList.GetIcon(ImageIndex,itimage); Result := ico; } end;

示例用法

g: TGraphic; g := ImageListGetGraphic(ImageList1,7); Image1.Picture.Graphic := g; g.Free;

注意 :任何代码发布到公共领域。 不需要归属

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐