-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathumain.pas
More file actions
215 lines (189 loc) · 7.11 KB
/
umain.pas
File metadata and controls
215 lines (189 loc) · 7.11 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
unit umain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Dialogs, ComCtrls,
BGRABitmap, BGRABitmapTypes, BGRAShape, BCLabel, BCButton, LCLIntF, StdCtrls;
type
{ TfrmMain }
TfrmMain = class(TForm)
BCButton1: TButton;
BCLabel1: TBCLabel;
BGRAShape1: TBGRAShape;
OpenDialog1: TOpenDialog;
ProgressBar1: TProgressBar;
SelectDirectoryDialog1: TSelectDirectoryDialog;
procedure BCButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
private
SourceFile: string;
DestDir: string;
procedure SaveIcons;
procedure SelectOutput(srcFile: string);
procedure ProcessIcons;
procedure ProcessIconsTerminate(Sender: TObject);
public
end;
var
frmMain: TfrmMain;
implementation
{$R *.lfm}
{ TfrmMain }
procedure TfrmMain.FormDropFiles(Sender: TObject; const FileNames: array of string);
begin
if not ProgressBar1.Visible then
SelectOutput(FileNames[0]);
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
ProgressBar1.Visible := False;
ProgressBar1.Style := TProgressBarStyle.pbstMarquee;
end;
procedure TfrmMain.BCButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
SelectOutput(OpenDialog1.FileName);
end;
end;
procedure TfrmMain.SaveIcons;
begin
ProgressBar1.Visible := True;
BCButton1.Visible := False;
BCLabel1.Caption := 'Saving icons...';
TThread.ExecuteInThread(@ProcessIcons, @ProcessIconsTerminate);
end;
procedure TfrmMain.SelectOutput(srcFile: string);
begin
case LowerCase(ExtractFileExt(srcFile)) of
'.png', '.bmp', '.jpg':
begin
if SelectDirectoryDialog1.Execute then
begin
SourceFile := srcFile;
DestDir := IncludeTrailingPathDelimiter(SelectDirectoryDialog1.FileName);
SaveIcons;
end;
end
else
ShowMessage('File extension "' + ExtractFileExt(srcFile) +
'" not supported. Supported .png, .bmp and .jpg.');
end;
end;
procedure TfrmMain.ProcessIcons;
function DoCalculateDestRect(AWidth, AHeight, ADestWidth, ADestHeight: integer): TRect;
var
PicWidth: integer;
PicHeight: integer;
ImgWidth: integer;
ImgHeight: integer;
w: integer;
h: integer;
begin
PicWidth := AWidth;
PicHeight := AHeight;
ImgWidth := ADestWidth;
ImgHeight := ADestHeight;
w := ImgWidth;
h := (PicHeight * w) div PicWidth;
if h > ImgHeight then
begin
h := ImgHeight;
w := (PicWidth * h) div PicHeight;
end;
PicWidth := w;
PicHeight := h;
Result := Rect(0, 0, PicWidth, PicHeight);
OffsetRect(Result, (ImgWidth - PicWidth) div 2, (ImgHeight - PicHeight) div 2);
end;
procedure SaveIcon(s: string; w, h: integer; src: TBGRABitmap; c: TBGRAPixel);
var
bmp, tmp: TBGRABitmap;
r: TRect;
begin
bmp := TBGRABitmap.Create(w, h, c);
r := DoCalculateDestRect(src.Width, src.Height, w, h);
src.ResampleFilter := rfBestQuality;
tmp := src.Resample(r.Width, r.Height) as TBGRABitmap;
bmp.PutImage(r.Left, r.Top, tmp, dmDrawWithTransparency);
tmp.Free;
bmp.SaveToFile(DestDir + s + '.png');
bmp.Free;
end;
var
bmp: TBGRABitmap;
begin
bmp := TBGRABitmap.Create(SourceFile);
try
// Android Icons
SaveIcon('android_36x36_ldpi', 36, 36, bmp, BGRAPixelTransparent);
SaveIcon('android_48x48_mdpi', 48, 48, bmp, BGRAPixelTransparent);
SaveIcon('android_72x72_hdpi', 72, 72, bmp, BGRAPixelTransparent);
SaveIcon('android_96x96_xhdpi', 96, 96, bmp, BGRAPixelTransparent);
SaveIcon('android_144x144_xxhdpi', 144, 144, bmp, BGRAPixelTransparent);
// Android Splash
SaveIcon('android_splash_426x320_small', 426, 320, bmp, BGRABlack);
SaveIcon('android_splash_470x320_normal', 470, 320, bmp, BGRABlack);
SaveIcon('android_splash_640x480_large', 640, 480, bmp, BGRABlack);
SaveIcon('android_splash_960x720_xlarge', 960, 720, bmp, BGRABlack);
// iOS Icons
SaveIcon('ios_57x57', 57, 57, bmp, BGRAPixelTransparent);
SaveIcon('ios_60x60', 60, 60, bmp, BGRAPixelTransparent);
SaveIcon('ios_72x72', 72, 72, bmp, BGRAPixelTransparent);
SaveIcon('ios_76x76', 76, 76, bmp, BGRAPixelTransparent);
SaveIcon('ios_87x87', 87, 87, bmp, BGRAPixelTransparent);
SaveIcon('ios_114x114', 114, 114, bmp, BGRAPixelTransparent);
SaveIcon('ios_120x120', 120, 120, bmp, BGRAPixelTransparent);
SaveIcon('ios_144x144', 144, 144, bmp, BGRAPixelTransparent);
SaveIcon('ios_152x152', 152, 152, bmp, BGRAPixelTransparent);
SaveIcon('ios_167x167', 167, 167, bmp, BGRAPixelTransparent);
SaveIcon('ios_180x180', 180, 180, bmp, BGRAPixelTransparent);
// iOS Launch Image
SaveIcon('ios_launch_320x480', 320, 480, bmp, BGRABlack);
SaveIcon('ios_launch_640x960', 640, 960, bmp, BGRABlack);
SaveIcon('ios_launch_640x1136', 640, 1136, bmp, BGRABlack);
SaveIcon('ios_launch_750x1334', 750, 1334, bmp, BGRABlack);
SaveIcon('ios_launch_768x1004', 768, 1004, bmp, BGRABlack);
SaveIcon('ios_launch_768x1024', 768, 1024, bmp, BGRABlack);
SaveIcon('ios_launch_1004x768', 1004, 768, bmp, BGRABlack);
SaveIcon('ios_launch_1024x748', 1024, 748, bmp, BGRABlack);
SaveIcon('ios_launch_1024x768', 1024, 768, bmp, BGRABlack);
SaveIcon('ios_launch_1536x2008', 1536, 2008, bmp, BGRABlack);
SaveIcon('ios_launch_1536x2048', 1536, 2048, bmp, BGRABlack);
SaveIcon('ios_launch_2008x1536', 2008, 1536, bmp, BGRABlack);
SaveIcon('ios_launch_2048x1536', 2048, 1536, bmp, BGRABlack);
SaveIcon('ios_launch_1496x2048', 1496, 2048, bmp, BGRABlack);
SaveIcon('ios_launch_2048x1496', 2048, 1496, bmp, BGRABlack);
SaveIcon('ios_launch_1668x2388', 1668, 2388, bmp, BGRABlack);
SaveIcon('ios_launch_2388x1668', 2388, 1668, bmp, BGRABlack);
SaveIcon('ios_launch_1668x2224', 1668, 2224, bmp, BGRABlack);
SaveIcon('ios_launch_2224x1668', 2224, 1668, bmp, BGRABlack);
SaveIcon('ios_launch_1334x750', 1334, 750, bmp, BGRABlack);
SaveIcon('ios_launch_828x1792', 828, 1792, bmp, BGRABlack);
SaveIcon('ios_launch_1792x828', 1792, 828, bmp, BGRABlack);
SaveIcon('ios_launch_1125x2436', 1125, 2436, bmp, BGRABlack);
SaveIcon('ios_launch_1136x640', 1136, 640, bmp, BGRABlack);
SaveIcon('ios_launch_2436x1125', 2436, 1125, bmp, BGRABlack);
SaveIcon('ios_launch_1242x2208', 1242, 2208, bmp, BGRABlack);
SaveIcon('ios_launch_2208x1242', 2208, 1242, bmp, BGRABlack);
SaveIcon('ios_launch_1242x2688', 1242, 2688, bmp, BGRABlack);
SaveIcon('ios_launch_2688x1242', 2688, 1242, bmp, BGRABlack);
SaveIcon('ios_launch_2048x2732', 2048, 2732, bmp, BGRABlack);
SaveIcon('ios_launch_2732x2048', 2732, 2048, bmp, BGRABlack);
// iOS Spotlight Search Icon
SaveIcon('ios_spotlight_29x29', 29, 29, bmp, BGRABlack);
SaveIcon('ios_spotlight_40x40', 40, 40, bmp, BGRABlack);
SaveIcon('ios_spotlight_58x58', 58, 58, bmp, BGRABlack);
SaveIcon('ios_spotlight_80x80', 80, 80, bmp, BGRABlack);
finally
bmp.Free;
end;
end;
procedure TfrmMain.ProcessIconsTerminate(Sender: TObject);
begin
ProgressBar1.Visible := False;
BCLabel1.Caption := 'Done! Drop another image here';
BCButton1.Visible := True;
end;
end.