forked from e-delphi/VCL2FMX
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathImageList.pas
More file actions
106 lines (90 loc) · 2.85 KB
/
ImageList.pas
File metadata and controls
106 lines (90 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{**********************************************}
{ }
{ Eduardo Rodrigues }
{ 18/09/2019 }
{ }
{**********************************************}
unit ImageList;
interface
uses
System.Classes, System.Generics.Collections, Vcl.Imaging.PngImage;
type
TImageList = class(TObjectList<TPngImage>);
function EncodeImageList(AImageList: TImageList; APad: String): String;
procedure ParseImageList(AData: TMemoryStream; AImageList: TImageList);
implementation
uses
System.SysUtils, Vcl.ImgList, Vcl.Graphics, PatchLib;
type
TImageListAccess = class(Vcl.ImgList.TCustomImageList)
end;
procedure ParseImageList(AData: TMemoryStream; AImageList: TImageList);
var
ImgList: TImageListAccess;
Png: TPngImage;
Bmp: TBitmap;
I: Integer;
begin
ImgList := TImageListAccess.Create(nil);
try
TImageListAccess(ImgList).ReadData(AData);
for I := 0 to Pred(ImgList.Count) do
begin
Bmp := TBitmap.Create;
try
ImgList.GetBitmap(I, Bmp);
Png := TPngImage.Create;
Png.Assign(Bmp);
AImageList.Add(Png);
finally
FreeAndNil(Bmp);
end;
end;
finally
ImgList.Free;
end;
end;
function EncodeImageList(AImageList: TImageList; APad: String): String;
var
Stream: TMemoryStream;
Data: String;
i: Integer;
begin
Stream := TMemoryStream.Create;
try
Result := APad + ' Source = <';
// Adiciona as imagens
for i := 0 to AImageList.Count - 1 do
begin
Stream.Clear;
AImageList[i].SaveToStream(Stream);
Data := BreakIntoLines(StreamToHex(Stream), APad + ' ');
Result := Result +
CRLF + APad + ' item ' +
CRLF + APad + ' MultiResBitmap = < ' +
CRLF + APad + ' item ' +
CRLF + APad + ' Width = ' + AImageList[i].Height.ToString +
CRLF + APad + ' Height = ' + AImageList[i].Width.ToString +
CRLF + APad + ' PNG = {' + Data + '}' +
CRLF + APad + ' end>' +
CRLF + APad + ' Name = ''Item' + i.toString + '''' +
CRLF + APad + ' end';
end;
Result := Result + '>' + CRLF + APad + ' Destination = <';
// Adiciona os itens
for i := 0 to AImageList.Count - 1 do
Result := Result +
CRLF + APad + ' item ' +
CRLF + APad + ' Layers = < ' +
CRLF + APad + ' item ' +
CRLF + APad + ' Name = ''Item' + i.toString + '''' +
CRLF + APad + ' SourceRect.Right = ' + AImageList[i].Width.ToString +
CRLF + APad + ' SourceRect.Bottom = ' + AImageList[i].Height.ToString +
CRLF + APad + ' end>' +
CRLF + APad + ' end';
Result := Result + '>';
finally
Stream.Free;
end;
end;
end.