cxImageList运行时加载png图片和编辑
cxImageList运行时加载png图片和编辑
uses IOUtils, dxGDIPlusClasses, cxImageListEditor;
procedure TFormMain.LoadPngs(AImageList: TcxImageList; const AModule: string; ASourceSize: Integer = 128; ADestSize: Integer = 64); var PicsPath, Path: String; Png: TdxPNGImage; Bmp, destBmp: TcxAlphaBitmap; begin AImageList.SetSize(ADestSize, ADestSize); PicsPath := ExtractFilePath(ExtractFilePath(ParamStr(0))) + 'picture' + PathDelim + AModule; for Path in TDirectory.GetFiles(PicsPath, '*.png') do begin if FileExists(Path) then begin Png := TdxPNGImage.Create; Bmp := TcxAlphaBitmap.Create; destBmp := TcxAlphaBitmap.Create; try Png.SetSize(ASourceSize, ASourceSize); Bmp.SetSize(ASourceSize, ASourceSize); Png.LoadFromFile(Path); Bmp.Assign(Png); destBmp := TcxAlphaBitmap.CreateSize(ADestSize, ADestSize); cxSmoothResizeBitmap(Bmp, destBmp, true); AImageList.Add(destBmp, nil); finally Png.Free; Bmp.Free; destBmp.Free; end; end else ShowMessage('No Image:' + Path); end; end;
procedure TForm1.Button2Click(Sender: TObject); var AEditor: TcxImageListEditor; begin AEditor := TcxImageListEditor.Create; try AEditor.Edit(cxImageList1); finally FreeAndNil(AEditor); end; end;
procedure TFormMain.LoadIcos(AImageList: TcxImageList; const AModule: string; ASize: Integer = 64); var LPicsPath, LPath: String; LIcon: TIcon; begin if AImageList = nil then Exit; AImageList.SetSize(ASize, ASize); try LPicsPath := ExtractFilePath(ExtractFilePath(ParamStr(0))) + 'picture' + PathDelim + AModule; for LPath in TDirectory.GetFiles(LPicsPath, '*.ico') do begin if FileExists(LPath) then begin LIcon := TIcon.Create; try LIcon.SetSize(ASize, ASize); LIcon.LoadFromFile(LPath); AImageList.AddIcon(LIcon); finally LIcon.Free; end; end else ShowMessage('No image:' + LPath); end; except end; end;
procedure TFormMain.LoadBmps(AImageList: TcxImageList; const AModule: string; ASourceSize: Integer = 128; ADestSize: Integer = 64); var PicsPath, Path: String; Bmp, destBmp: TcxAlphaBitmap; begin AImageList.SetSize(ADestSize, ADestSize); PicsPath := ExtractFilePath(ExtractFilePath(ParamStr(0))) + 'picture' + PathDelim + AModule; for Path in TDirectory.GetFiles(PicsPath, '*.bmp') do begin if FileExists(Path) then begin Bmp := TcxAlphaBitmap.Create; destBmp := TcxAlphaBitmap.Create; try Bmp.SetSize(ASourceSize, ASourceSize); Bmp.LoadFromFile(Path); destBmp := TcxAlphaBitmap.CreateSize(ADestSize, ADestSize); cxSmoothResizeBitmap(Bmp, destBmp, true); AImageList.Add(destBmp, nil); finally Bmp.Free; destBmp.Free; end; end else ShowMessage('No Image:' + Path); end; end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/18867631

浙公网安备 33010602011771号