关于资源图片文件与DLL到Imagelist

unit udmImage;

interface

uses
  Windows, SysUtils, Classes, ImgList, Controls, Graphics;

type
  TdmImage = class(TDataModule)
    ImgLst16: TImageList;
    procedure DataModuleCreate(Sender: TObject);
  private
    {装载16×16的图标资源}
    procedure LoadIcon16;
  public

  end;

var
  dmImage: TdmImage;

implementation

{$R *.dfm}

procedure EnumResNamesProc(AMod: HModule; ResType: PChar; ResName: PChar; List: TStrings); stdcall;
begin
  List.Add(ResName);
end;

const
  sDllName = 'HsIcon16.Dll';
 
procedure TdmImage.LoadIcon16;
var
  Icon: TIcon;
  I: Integer;
  HResDll: THandle;
  List: TStringList;
 
  procedure LoadResIcon(ResName: string);
  var
    Stream: TResourceStream;
  begin
    Stream := TResourceStream.Create(HResDll, ResName, 'BMP');
    try
      Icon.LoadFromStream(Stream);
      ImgLst16.AddIcon(Icon);
    finally
      Stream.Free;
    end;
  end;
 
begin
  HResDll := LoadLibrary(sDllName);
  try
    if HResDll <> 0 then
    begin
      List := TStringList.Create;
      try
        EnumResourceNames(HResDll, 'BMP', @EnumResNamesProc, Integer(List));
        List.Sorted := True;
        Icon := TIcon.Create;
        try
          for I := 0 to List.Count - 1 do LoadResIcon(List[I]);
        finally
          Icon.Free;
        end;
      finally
        List.Free;
      end;
    end;
  finally
    if HResDll <> 0 then FreeLibrary(HResDll);
  end;
end;

procedure TdmImage.DataModuleCreate(Sender: TObject);
begin
  LoadIcon16;
end;

end. 

 

将ImageList的图片保存到本地:

procedure TForm1.Button1Click(Sender: TObject);
var
  spath: string;
begin
  spath := ExtractFilePath(Application.ExeName) + 'imagelist/';
  for i := 0 to ImgLst16.Count - 1 do
  begin
    Image1.Width := ImgLst16.Width;
    Image1.Height := ImgLst16.Height;
    ImgLst16.GetBitmap(i, Image1.Picture.Bitmap);
    Image1.Picture.Bitmap.SaveToFile(spath + IntToStr(i) + '.bmp');
    Image1.Picture.Bitmap := nil;
    Image1.Refresh;
    Image1.Repaint;
    Application.ProcessMessages;

  end;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值