如何在delphi中将图标转换为png与alpha透明度? [英] How to convert icon to png with alpha transparency in delphi?

查看:560
本文介绍了如何在delphi中将图标转换为png与alpha透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码将从文件中提取图标并将其转换为png,但没有Alpha透明度。

The code below will extract icon from file and convert it to png but without alpha transparency ?

var
   IconIndex : word;
   icon:TIcon;
   png:TPngImage;
   bmp:TBitmap;
begin
  IconIndex := 0;
  icon := TIcon.Create;
  icon.Handle := ExtractAssociatedIcon(hInstance,pChar(Edit1.Text), IconIndex) ;
  bmp:= TBitmap.Create;
  bmp.LoadFromFile('blank.bmp');
  DrawIcon(bmp.Canvas.Handle, 0, 0, icon.Handle) ;
  png := TPngImage.Create();
  png.Assign(bmp);
  png.SaveToFile('icon.png');
end;


推荐答案

PngComponents 包含一个单位PngFunctions.pas,您可以在这里查看

The PngComponents contain a unit PngFunctions.pas, where you can have a look at

procedure ConvertToPNG(Source:TGraphic; out Dest:TPngImage);

在那里可以找到转换TIcon的代码进入TPngImage - 或者只是使用该过程。

There you can find the code to convert a TIcon into a TPngImage - or just use that procedure.

这篇关于如何在delphi中将图标转换为png与alpha透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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