Delphi 2009 有了pngimage、GIFImg 单元, 可以直接使用 png 和 gif 图片了;
如果是设计时给 TImage 装载 png 图片, Delphi 会自动调用 pngimage 单元完成加载, 那动态调用呢?
当然首先要uses pngimage, 然后:
--------------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, pngimage;
type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
PngBit: TPngImage;
begin
PngBit := TPngImage.Create;
PngBit.LoadFromFile('c:\temp\test.png');
Image1.Picture.Graphic := PngBit;
PngBit.Free;
end;
end.