Develop and Download Open Source Software

Browse Subversion Repository

Contents of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations) (download) (as text)
Thu Jul 16 20:20:19 2015 UTC (8 years, 7 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 4868 byte(s)
重大なエラー発生
1 unit Unit1;
2
3 interface
4
5 uses
6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
7 System.Classes, Vcl.Graphics,
8 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtDlgs, Vcl.StdCtrls, Vcl.ExtCtrls,
9 Vcl.ComCtrls, Vcl.Imaging.pngImage;
10
11 type
12 TForm1 = class(TForm)
13 Image1: TImage;
14 Button1: TButton;
15 OpenPictureDialog1: TOpenPictureDialog;
16 Edit1: TEdit;
17 UpDown1: TUpDown;
18 Label1: TLabel;
19 Button2: TButton;
20 Label2: TLabel;
21 Button3: TButton;
22 SavePictureDialog1: TSavePictureDialog;
23 CheckBox1: TCheckBox;
24 procedure Button1Click(Sender: TObject);
25 procedure FormCreate(Sender: TObject);
26 procedure FormDestroy(Sender: TObject);
27 procedure Button2Click(Sender: TObject);
28 procedure Button3Click(Sender: TObject);
29 procedure UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
30 NewValue: Integer; Direction: TUpDownDirection);
31 procedure CheckBox1Click(Sender: TObject);
32 private
33 procedure Execute(aCount: Integer);
34 { Private ���� }
35 public
36 { Public ���� }
37 List: TList;
38 end;
39
40 var
41 Form1: TForm1;
42
43 implementation
44
45 {$R *.dfm}
46
47 procedure TForm1.Button1Click(Sender: TObject);
48 var
49 bmp1, bmp2: TBitmap;
50 r: TRect;
51 i, j, k: Integer;
52 procedure LoadToBitmap(FileName: TFileName; var bmp: TBitmap);
53 var
54 s: TPngImage;
55 p: TPicture;
56 begin
57 if ExtractFileExt(FileName) = '.png' then
58 begin
59 s := TPngImage.Create;
60 s.LoadFromFile(FileName);
61 bmp.Width := s.Width;
62 bmp.Height := s.Height;
63 s.Draw(bmp.Canvas, Rect(0, 0, bmp.Width, bmp.Height));
64 end
65 else
66 begin
67 p := TPicture.Create;
68 p.LoadFromFile(FileName);
69 bmp.Assign(p.Graphic);
70 end;
71 end;
72
73 begin
74 if OpenPictureDialog1.Execute = true then
75 for i := 0 to OpenPictureDialog1.Files.Count - 1 do
76 begin
77 bmp1 := TBitmap.Create;
78 bmp2 := TBitmap.Create;
79 try
80 LoadToBitmap(OpenPictureDialog1.Files[i], bmp2);
81 if CheckBox1.Checked = true then
82 begin
83 if bmp2.Width < bmp2.Height then
84 begin
85 j := (bmp2.Height - bmp2.Width) div 2;
86 k := bmp2.Width;
87 r := Rect(0, j, bmp2.Width, bmp2.Height - j);
88 end
89 else
90 begin
91 j := (bmp2.Width - bmp2.Height) div 2;
92 k := bmp2.Height;
93 r := Rect(j, 0, bmp2.Width - j, bmp2.Height);
94 end;
95 bmp1.Width := k;
96 bmp1.Height := k;
97 bmp1.Canvas.CopyRect(Rect(0, 0, bmp1.Width, bmp1.Height),
98 bmp2.Canvas, r);
99 end
100 else
101 bmp1.Assign(bmp2);
102 finally
103 bmp2.Free;
104 end;
105 List.Add(bmp1);
106 Label2.Caption := IntToStr(List.Count);
107 Execute(UpDown1.Position);
108 end;
109 end;
110
111 procedure TForm1.Button2Click(Sender: TObject);
112 var
113 i: Integer;
114 s: TBitmap;
115 begin
116 for i := 0 to List.Count - 1 do
117 TBitmap(List[i]).Free;
118 List.Clear;
119 Label2.Caption := '0';
120 s := Image1.Picture.Bitmap;
121 s.Canvas.FillRect(Rect(0, 0, s.Width, s.Height));
122 end;
123
124 procedure TForm1.Button3Click(Sender: TObject);
125 begin
126 if SavePictureDialog1.Execute = true then
127 Image1.Picture.Bitmap.SaveToFile(SavePictureDialog1.FileName);
128 end;
129
130 procedure TForm1.CheckBox1Click(Sender: TObject);
131 begin
132 if MessageDlg('������������������', mtCustom, [mbYes, mbNo], 0) = mrYes then
133 begin
134 Button2Click(Sender);
135 Button1Click(Sender);
136 end;
137 end;
138
139 procedure TForm1.FormCreate(Sender: TObject);
140 begin
141 List := TList.Create;
142 end;
143
144 procedure TForm1.FormDestroy(Sender: TObject);
145 begin
146 Button2Click(Sender);
147 List.Free;
148 end;
149
150 procedure TForm1.UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
151 NewValue: Integer; Direction: TUpDownDirection);
152 var
153 n: Integer;
154 begin
155 case Direction of
156 updUp:
157 n := UpDown1.Position + UpDown1.Increment;
158 updDown:
159 n := UpDown1.Position - UpDown1.Increment;
160 else
161 Exit;
162 end;
163 Execute(n);
164 end;
165
166 procedure TForm1.Execute(aCount: Integer);
167 var
168 i: Integer;
169 s: TBitmap;
170 bmp: TBitmap;
171 j: Integer;
172 k, m: Integer;
173 label Label1;
174 begin
175 if List.Count = 0 then
176 Exit
177 else
178 s := List[0];
179 m := List.Count div aCount;
180 bmp := TBitmap.Create;
181 try
182 bmp.Width := s.Width * m;
183 bmp.Height := s.Height * aCount;
184 k := 0;
185 for j := 0 to aCount - 1 do
186 for i := 0 to m - 1 do
187 begin
188 if k <= List.Count - 1 then
189 begin
190 s := List[k];
191 inc(k);
192 end
193 else
194 goto Label1;
195 bmp.Canvas.Draw(i * s.Width, j * s.Height, s);
196 end;
197 Label1:
198 Image1.Picture.Bitmap.Assign(bmp);
199 finally
200 bmp.Free;
201 end;
202 end;
203
204 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26