回答編集履歴
8
修正
test
CHANGED
@@ -124,11 +124,9 @@
|
|
124
124
|
|
125
125
|
result.Coalesce();
|
126
126
|
|
127
|
-
result.RemoveAt(0);
|
128
127
|
|
129
128
|
|
130
|
-
|
131
|
-
result.Write($"psd\\{String.Format("{0:D6}", i)}.png");
|
129
|
+
result[1].Write($"psd\\{String.Format("{0:D6}", i - 1)}.png");
|
132
130
|
|
133
131
|
}
|
134
132
|
|
7
修正
test
CHANGED
@@ -3,6 +3,60 @@
|
|
3
3
|
dlemstra様本当にありがとうございました。
|
4
4
|
|
5
5
|
|
6
|
+
|
7
|
+
dlemstra様に教えていただいたコード。(CodePlexがシャッドダウン?されるそうなので追記。)
|
8
|
+
|
9
|
+
```C#
|
10
|
+
|
11
|
+
using ImageMagick;
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
namespace psd
|
16
|
+
|
17
|
+
{
|
18
|
+
|
19
|
+
class Program
|
20
|
+
|
21
|
+
{
|
22
|
+
|
23
|
+
static void Main(string[] args)
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
using (MagickImageCollection imgs = new MagickImageCollection("psdfile.psd"))
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
foreach (MagickImage img in imgs)
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
img.GifDisposeMethod = GifDisposeMethod.Background;
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
imgs.Coalesce();
|
42
|
+
|
43
|
+
imgs.RemoveAt(0);
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
imgs.Write("pngfile%04d.png");
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```
|
6
60
|
|
7
61
|
私の質問のURL
|
8
62
|
|
6
修正
test
CHANGED
@@ -36,16 +36,6 @@
|
|
36
36
|
|
37
37
|
{
|
38
38
|
|
39
|
-
foreach (MagickImage img in imgs)
|
40
|
-
|
41
|
-
{
|
42
|
-
|
43
|
-
img.GifDisposeMethod = GifDisposeMethod.Background;
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
39
|
int width = imgs[0].Width;
|
50
40
|
|
51
41
|
int height = imgs[0].Height;
|
@@ -54,7 +44,7 @@
|
|
54
44
|
|
55
45
|
//imgs[0]は個人の好みで入れていない。
|
56
46
|
|
57
|
-
for(int i = 1; i < imgs.Count; i++)
|
47
|
+
for (int i = 1; i < imgs.Count; i++)
|
58
48
|
|
59
49
|
{
|
60
50
|
|
@@ -92,7 +82,7 @@
|
|
92
82
|
|
93
83
|
//定期的にGCを入れないとメモリの使用量が大変なことになる。
|
94
84
|
|
95
|
-
if(i % 20 == 0)
|
85
|
+
if (i % 20 == 0)
|
96
86
|
|
97
87
|
{
|
98
88
|
|
5
修正
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
{
|
60
60
|
|
61
|
-
//レイヤーの大きさを統一している。for_coal
|
61
|
+
//レイヤーの大きさを統一している。for_coalesceを外に置いておくとエラーが発生する。
|
62
62
|
|
63
63
|
using (MagickImageCollection result = new MagickImageCollection())
|
64
64
|
|
@@ -66,13 +66,13 @@
|
|
66
66
|
|
67
67
|
MagickColor transparent = new MagickColor(0, 0, 0, 0);
|
68
68
|
|
69
|
-
MagickImage for_coal
|
69
|
+
MagickImage for_coalesce = new MagickImage(transparent, width, height);
|
70
70
|
|
71
|
-
for_coal
|
71
|
+
for_coalesce.BackgroundColor = transparent;
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
result.Add(for_coal
|
75
|
+
result.Add(for_coalesce);
|
76
76
|
|
77
77
|
result.Add(imgs[i]);
|
78
78
|
|
@@ -114,4 +114,6 @@
|
|
114
114
|
|
115
115
|
}
|
116
116
|
|
117
|
+
|
118
|
+
|
117
119
|
```
|
4
修正
test
CHANGED
@@ -12,317 +12,101 @@
|
|
12
12
|
|
13
13
|
以前のコードだとPSDファイルによってはメモリを大量に使うことになっていたのでそれに対応しました。
|
14
14
|
|
15
|
-
このプログラムは公開されている沢山のプログラムを参考にして作っています。
|
16
|
-
|
17
|
-
|
18
|
-
|
19
15
|
```C#
|
20
16
|
|
21
17
|
using System;
|
22
18
|
|
23
|
-
using System.Collections.Generic;
|
24
|
-
|
25
|
-
using System.Linq;
|
26
|
-
|
27
|
-
using System.Text;
|
28
|
-
|
29
|
-
using System.Threading.Tasks;
|
30
|
-
|
31
|
-
using System.Windows;
|
32
|
-
|
33
|
-
using System.Windows.Controls;
|
34
|
-
|
35
|
-
using System.Windows.Data;
|
36
|
-
|
37
|
-
using System.Windows.Documents;
|
38
|
-
|
39
|
-
using System.Windows.Input;
|
40
|
-
|
41
|
-
using System.Windows.Media;
|
42
|
-
|
43
|
-
using System.Windows.Media.Imaging;
|
44
|
-
|
45
|
-
using System.Windows.Navigation;
|
46
|
-
|
47
|
-
using System.Windows.Shapes;
|
48
|
-
|
49
|
-
using System.IO;
|
50
|
-
|
51
19
|
using ImageMagick;
|
52
|
-
|
53
|
-
using System.Windows.Threading;
|
54
20
|
|
55
21
|
|
56
22
|
|
57
|
-
namespace
|
23
|
+
namespace psdconvert1
|
58
24
|
|
59
25
|
{
|
60
26
|
|
61
|
-
/// <summary>
|
62
|
-
|
63
|
-
/// MainWindow.xaml の相互作用ロジック
|
64
|
-
|
65
|
-
/// </summary>
|
66
|
-
|
67
|
-
|
27
|
+
class Program
|
68
28
|
|
69
29
|
{
|
70
30
|
|
71
|
-
|
31
|
+
static void Main(string[] args)
|
72
32
|
|
73
33
|
{
|
74
34
|
|
75
|
-
|
35
|
+
using (MagickImageCollection imgs = new MagickImageCollection("psd.psd"))
|
76
36
|
|
77
|
-
|
37
|
+
{
|
78
38
|
|
79
|
-
|
39
|
+
foreach (MagickImage img in imgs)
|
80
40
|
|
81
|
-
|
41
|
+
{
|
82
42
|
|
83
|
-
|
43
|
+
img.GifDisposeMethod = GifDisposeMethod.Background;
|
84
44
|
|
85
|
-
DispatcherTimer move_timer;
|
86
|
-
|
87
|
-
void move_timer_Tick(object sender, EventArgs e)
|
88
|
-
|
89
|
-
{
|
90
|
-
|
91
|
-
this.Next();
|
92
|
-
|
93
|
-
}
|
45
|
+
}
|
94
|
-
|
95
|
-
private void Clicked_Dialog(object sender, RoutedEventArgs e)
|
96
|
-
|
97
|
-
{
|
98
|
-
|
99
|
-
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
|
100
|
-
|
101
|
-
dlg.Title = "読み込むファイルを選択してください。";
|
102
|
-
|
103
|
-
dlg.DefaultExt = ".psd";
|
104
|
-
|
105
|
-
dlg.Filter = "PSDファイル(.psd)|*.psd";
|
106
46
|
|
107
47
|
|
108
48
|
|
109
|
-
|
49
|
+
int width = imgs[0].Width;
|
110
50
|
|
111
|
-
if (result == true)
|
112
|
-
|
113
|
-
{
|
114
|
-
|
115
|
-
thi
|
51
|
+
int height = imgs[0].Height;
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
private async void Clicked_Start(object sender, RoutedEventArgs e)
|
122
|
-
|
123
|
-
{
|
124
|
-
|
125
|
-
path = パス.Text;
|
126
|
-
|
127
|
-
if (path.Length > 1 && System.IO.File.Exists(path) == false)
|
128
|
-
|
129
|
-
{
|
130
|
-
|
131
|
-
MessageBox.Show("『" + System.IO.Path.GetFileNameWithoutExtension(path) + "』は存在しません。", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
await heavyLogicTaskAsync();
|
136
|
-
|
137
|
-
if (success == 1)
|
138
|
-
|
139
|
-
{
|
140
|
-
|
141
|
-
プログレスバー.Value = max;
|
142
|
-
|
143
|
-
MessageBox.Show("作業が完了しました。", "PSD", MessageBoxButton.OK, MessageBoxImage.None);
|
144
|
-
|
145
|
-
success = 0;
|
146
|
-
|
147
|
-
move_timer.Stop();
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
プログレスバー.Value = 0;
|
152
|
-
|
153
|
-
プログレスバー.Maximum = 100;
|
154
|
-
|
155
|
-
value_num = 0;
|
156
|
-
|
157
|
-
max = 0;
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
private Task heavyLogicTaskAsync()
|
162
|
-
|
163
|
-
{
|
164
|
-
|
165
|
-
return Task.Run(() => PSD_Convert());
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
public string path = null;
|
170
|
-
|
171
|
-
public int max = 0;
|
172
|
-
|
173
|
-
public int value_num = 0;
|
174
|
-
|
175
|
-
public int success = 0;
|
176
|
-
|
177
|
-
private void PSD_Convert()
|
178
|
-
|
179
|
-
{
|
180
52
|
|
181
53
|
|
182
54
|
|
183
|
-
|
55
|
+
//imgs[0]は個人の好みで入れていない。
|
184
56
|
|
185
|
-
{
|
186
|
-
|
187
|
-
|
57
|
+
for(int i = 1; i < imgs.Count; i++)
|
188
58
|
|
189
59
|
{
|
190
60
|
|
191
|
-
|
61
|
+
//レイヤーの大きさを統一している。for_coalraceを外に置いておくとエラーが発生する。
|
192
62
|
|
193
|
-
i
|
63
|
+
using (MagickImageCollection result = new MagickImageCollection())
|
194
64
|
|
195
65
|
{
|
196
66
|
|
67
|
+
MagickColor transparent = new MagickColor(0, 0, 0, 0);
|
68
|
+
|
197
|
-
M
|
69
|
+
MagickImage for_coalrace = new MagickImage(transparent, width, height);
|
70
|
+
|
71
|
+
for_coalrace.BackgroundColor = transparent;
|
198
72
|
|
199
73
|
|
200
74
|
|
201
|
-
tr
|
75
|
+
result.Add(for_coalrace);
|
202
76
|
|
203
|
-
|
77
|
+
result.Add(imgs[i]);
|
204
78
|
|
205
|
-
MagickImageCollection imgs = new MagickImageCollection(path);
|
206
79
|
|
207
|
-
foreach (MagickImage img in imgs)
|
208
80
|
|
209
|
-
|
81
|
+
result.Coalesce();
|
210
82
|
|
211
|
-
|
83
|
+
result.RemoveAt(0);
|
212
84
|
|
213
|
-
}
|
214
85
|
|
215
|
-
int Width = imgs[0].Width;
|
216
86
|
|
217
|
-
|
87
|
+
result.Write($"psd\\{String.Format("{0:D6}", i)}.png");
|
218
88
|
|
219
|
-
|
89
|
+
}
|
220
90
|
|
221
|
-
if (System.IO.Directory.Exists("converted") == false)
|
222
91
|
|
223
|
-
{
|
224
92
|
|
225
|
-
|
93
|
+
//定期的にGCを入れないとメモリの使用量が大変なことになる。
|
226
94
|
|
227
|
-
|
95
|
+
if(i % 20 == 0)
|
228
96
|
|
229
|
-
|
97
|
+
{
|
230
98
|
|
231
|
-
|
99
|
+
GC.Collect();
|
232
100
|
|
233
|
-
|
101
|
+
GC.WaitForPendingFinalizers();
|
234
102
|
|
235
|
-
}
|
236
|
-
|
237
|
-
max = imgs.Count;
|
238
|
-
|
239
|
-
move_timer.Start();
|
240
|
-
|
241
|
-
for (int count = 1; count < imgs.Count; ++count)
|
242
|
-
|
243
|
-
{
|
244
|
-
|
245
|
-
using (MagickImageCollection results = new MagickImageCollection())
|
246
|
-
|
247
|
-
{
|
248
|
-
|
249
|
-
MagickImage baseimage = new MagickImage(new MagickColor(0, 0, 0, 0), Width, Height);
|
250
|
-
|
251
|
-
baseimage.BackgroundColor = new MagickColor(0, 0, 0, 0);
|
252
|
-
|
253
|
-
results.Add(baseimage);
|
254
|
-
|
255
|
-
results.Add(imgs[count]);
|
256
|
-
|
257
|
-
results.Coalesce();
|
258
|
-
|
259
|
-
results.RemoveAt(0);
|
260
|
-
|
261
|
-
string num = String.Format("{0:D6}", count);
|
262
|
-
|
263
|
-
results.Write("converted/" + name + "/" + num + ".png");
|
264
|
-
|
265
|
-
results.Dispose();
|
266
|
-
|
267
|
-
baseimage.Dispose();
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
GC_Count++;
|
272
|
-
|
273
|
-
if (GC_Count >= 20)
|
274
|
-
|
275
|
-
{
|
276
|
-
|
277
|
-
|
103
|
+
GC.Collect();
|
278
|
-
|
279
|
-
GC.WaitForPendingFinalizers();
|
280
|
-
|
281
|
-
GC.Collect();
|
282
|
-
|
283
|
-
GC_Count = 0;
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
value_num++;
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
GC.Collect();
|
292
|
-
|
293
|
-
GC.WaitForPendingFinalizers();
|
294
|
-
|
295
|
-
GC.Collect();
|
296
|
-
|
297
|
-
success = 1;
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
catch (ImageMagick.MagickCorruptImageErrorException)
|
302
|
-
|
303
|
-
{
|
304
|
-
|
305
|
-
MessageBox.Show("『" + name + "』を開けません。", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
|
306
|
-
|
307
|
-
}
|
308
104
|
|
309
105
|
}
|
310
106
|
|
311
107
|
}
|
312
108
|
|
313
109
|
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
private void Next()
|
320
|
-
|
321
|
-
{
|
322
|
-
|
323
|
-
プログレスバー.Maximum = max - 1;
|
324
|
-
|
325
|
-
プログレスバー.Value = value_num;
|
326
110
|
|
327
111
|
}
|
328
112
|
|
@@ -331,43 +115,3 @@
|
|
331
115
|
}
|
332
116
|
|
333
117
|
```
|
334
|
-
|
335
|
-
```XAML
|
336
|
-
|
337
|
-
<Window x:Class="PSDConverter4.MainWindow"
|
338
|
-
|
339
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
340
|
-
|
341
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
342
|
-
|
343
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
344
|
-
|
345
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
346
|
-
|
347
|
-
xmlns:local="clr-namespace:PSDConverter4"
|
348
|
-
|
349
|
-
mc:Ignorable="d"
|
350
|
-
|
351
|
-
Title="PSD" Height="170" Width="250"
|
352
|
-
|
353
|
-
Background="Silver"
|
354
|
-
|
355
|
-
ResizeMode="NoResize">
|
356
|
-
|
357
|
-
<Grid>
|
358
|
-
|
359
|
-
<Label x:Name="読み込みファイル名" Content="File Path" HorizontalAlignment="Left" Margin="10,16,0,0" VerticalAlignment="Top" Width="61"/>
|
360
|
-
|
361
|
-
<TextBox x:Name="パス" HorizontalAlignment="Left" Height="23" Margin="71,19,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120"/>
|
362
|
-
|
363
|
-
<Button x:Name="ダイアログ" Content="・・・" HorizontalAlignment="Left" Margin="201,19,0,0" VerticalAlignment="Top" Width="22" RenderTransformOrigin="1.205,0.45" Height="23" Click="Clicked_Dialog"/>
|
364
|
-
|
365
|
-
<Button x:Name="スタート" Content="START" HorizontalAlignment="Left" Margin="10,92,0,0" VerticalAlignment="Top" Width="213" Height="24" Click="Clicked_Start"/>
|
366
|
-
|
367
|
-
<ProgressBar Name="プログレスバー" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,58,0,0" Height="16" Width="213" Minimum="0" Maximum="100" IsIndeterminate="False"/>
|
368
|
-
|
369
|
-
</Grid>
|
370
|
-
|
371
|
-
</Window>
|
372
|
-
|
373
|
-
```
|
3
補足
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
以前のコードだとPSDファイルによってはメモリを大量に使うことになっていたのでそれに対応しました。
|
14
14
|
|
15
|
-
このプログラムは公開されている沢山のプログラムを参考にして作
|
15
|
+
このプログラムは公開されている沢山のプログラムを参考にして作っています。
|
16
16
|
|
17
17
|
|
18
18
|
|
2
補足
test
CHANGED
@@ -12,6 +12,10 @@
|
|
12
12
|
|
13
13
|
以前のコードだとPSDファイルによってはメモリを大量に使うことになっていたのでそれに対応しました。
|
14
14
|
|
15
|
+
このプログラムは公開されている沢山のプログラムを参考にして作られています。
|
16
|
+
|
17
|
+
|
18
|
+
|
15
19
|
```C#
|
16
20
|
|
17
21
|
using System;
|
1
補足
test
CHANGED
@@ -7,3 +7,363 @@
|
|
7
7
|
私の質問のURL
|
8
8
|
|
9
9
|
[How to write Background?](https://magick.codeplex.com/discussions/660412)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
以前のコードだとPSDファイルによってはメモリを大量に使うことになっていたのでそれに対応しました。
|
14
|
+
|
15
|
+
```C#
|
16
|
+
|
17
|
+
using System;
|
18
|
+
|
19
|
+
using System.Collections.Generic;
|
20
|
+
|
21
|
+
using System.Linq;
|
22
|
+
|
23
|
+
using System.Text;
|
24
|
+
|
25
|
+
using System.Threading.Tasks;
|
26
|
+
|
27
|
+
using System.Windows;
|
28
|
+
|
29
|
+
using System.Windows.Controls;
|
30
|
+
|
31
|
+
using System.Windows.Data;
|
32
|
+
|
33
|
+
using System.Windows.Documents;
|
34
|
+
|
35
|
+
using System.Windows.Input;
|
36
|
+
|
37
|
+
using System.Windows.Media;
|
38
|
+
|
39
|
+
using System.Windows.Media.Imaging;
|
40
|
+
|
41
|
+
using System.Windows.Navigation;
|
42
|
+
|
43
|
+
using System.Windows.Shapes;
|
44
|
+
|
45
|
+
using System.IO;
|
46
|
+
|
47
|
+
using ImageMagick;
|
48
|
+
|
49
|
+
using System.Windows.Threading;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
namespace PSDConverter4
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
/// <summary>
|
58
|
+
|
59
|
+
/// MainWindow.xaml の相互作用ロジック
|
60
|
+
|
61
|
+
/// </summary>
|
62
|
+
|
63
|
+
public partial class MainWindow : Window
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
public MainWindow()
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
InitializeComponent();
|
72
|
+
|
73
|
+
move_timer = new DispatcherTimer();
|
74
|
+
|
75
|
+
move_timer.Interval = TimeSpan.FromSeconds(1);
|
76
|
+
|
77
|
+
move_timer.Tick += move_timer_Tick;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
DispatcherTimer move_timer;
|
82
|
+
|
83
|
+
void move_timer_Tick(object sender, EventArgs e)
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
this.Next();
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
private void Clicked_Dialog(object sender, RoutedEventArgs e)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
|
96
|
+
|
97
|
+
dlg.Title = "読み込むファイルを選択してください。";
|
98
|
+
|
99
|
+
dlg.DefaultExt = ".psd";
|
100
|
+
|
101
|
+
dlg.Filter = "PSDファイル(.psd)|*.psd";
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
Nullable<bool> result = dlg.ShowDialog();
|
106
|
+
|
107
|
+
if (result == true)
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
this.パス.Text = dlg.FileName;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
private async void Clicked_Start(object sender, RoutedEventArgs e)
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
path = パス.Text;
|
122
|
+
|
123
|
+
if (path.Length > 1 && System.IO.File.Exists(path) == false)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
MessageBox.Show("『" + System.IO.Path.GetFileNameWithoutExtension(path) + "』は存在しません。", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
await heavyLogicTaskAsync();
|
132
|
+
|
133
|
+
if (success == 1)
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
プログレスバー.Value = max;
|
138
|
+
|
139
|
+
MessageBox.Show("作業が完了しました。", "PSD", MessageBoxButton.OK, MessageBoxImage.None);
|
140
|
+
|
141
|
+
success = 0;
|
142
|
+
|
143
|
+
move_timer.Stop();
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
プログレスバー.Value = 0;
|
148
|
+
|
149
|
+
プログレスバー.Maximum = 100;
|
150
|
+
|
151
|
+
value_num = 0;
|
152
|
+
|
153
|
+
max = 0;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
private Task heavyLogicTaskAsync()
|
158
|
+
|
159
|
+
{
|
160
|
+
|
161
|
+
return Task.Run(() => PSD_Convert());
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
public string path = null;
|
166
|
+
|
167
|
+
public int max = 0;
|
168
|
+
|
169
|
+
public int value_num = 0;
|
170
|
+
|
171
|
+
public int success = 0;
|
172
|
+
|
173
|
+
private void PSD_Convert()
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
if (path != null)
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
if (path.Length > 1)
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
string name = System.IO.Path.GetFileNameWithoutExtension(path);
|
188
|
+
|
189
|
+
if (System.IO.File.Exists(path) == true)
|
190
|
+
|
191
|
+
{
|
192
|
+
|
193
|
+
MessageBox.Show("『" + name + "』をPNGに変換します。", "PSD", MessageBoxButton.OK, MessageBoxImage.None);
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
try
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
MagickImageCollection imgs = new MagickImageCollection(path);
|
202
|
+
|
203
|
+
foreach (MagickImage img in imgs)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
img.GifDisposeMethod = GifDisposeMethod.Background;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
int Width = imgs[0].Width;
|
212
|
+
|
213
|
+
int Height = imgs[0].Height;
|
214
|
+
|
215
|
+
int GC_Count = 0;
|
216
|
+
|
217
|
+
if (System.IO.Directory.Exists("converted") == false)
|
218
|
+
|
219
|
+
{
|
220
|
+
|
221
|
+
System.IO.Directory.CreateDirectory("converted");
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
if (System.IO.Directory.Exists("converted/" + name) == false)
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
System.IO.Directory.CreateDirectory("converted/" + name);
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
max = imgs.Count;
|
234
|
+
|
235
|
+
move_timer.Start();
|
236
|
+
|
237
|
+
for (int count = 1; count < imgs.Count; ++count)
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
using (MagickImageCollection results = new MagickImageCollection())
|
242
|
+
|
243
|
+
{
|
244
|
+
|
245
|
+
MagickImage baseimage = new MagickImage(new MagickColor(0, 0, 0, 0), Width, Height);
|
246
|
+
|
247
|
+
baseimage.BackgroundColor = new MagickColor(0, 0, 0, 0);
|
248
|
+
|
249
|
+
results.Add(baseimage);
|
250
|
+
|
251
|
+
results.Add(imgs[count]);
|
252
|
+
|
253
|
+
results.Coalesce();
|
254
|
+
|
255
|
+
results.RemoveAt(0);
|
256
|
+
|
257
|
+
string num = String.Format("{0:D6}", count);
|
258
|
+
|
259
|
+
results.Write("converted/" + name + "/" + num + ".png");
|
260
|
+
|
261
|
+
results.Dispose();
|
262
|
+
|
263
|
+
baseimage.Dispose();
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
GC_Count++;
|
268
|
+
|
269
|
+
if (GC_Count >= 20)
|
270
|
+
|
271
|
+
{
|
272
|
+
|
273
|
+
GC.Collect();
|
274
|
+
|
275
|
+
GC.WaitForPendingFinalizers();
|
276
|
+
|
277
|
+
GC.Collect();
|
278
|
+
|
279
|
+
GC_Count = 0;
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
value_num++;
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
GC.Collect();
|
288
|
+
|
289
|
+
GC.WaitForPendingFinalizers();
|
290
|
+
|
291
|
+
GC.Collect();
|
292
|
+
|
293
|
+
success = 1;
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
catch (ImageMagick.MagickCorruptImageErrorException)
|
298
|
+
|
299
|
+
{
|
300
|
+
|
301
|
+
MessageBox.Show("『" + name + "』を開けません。", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
private void Next()
|
316
|
+
|
317
|
+
{
|
318
|
+
|
319
|
+
プログレスバー.Maximum = max - 1;
|
320
|
+
|
321
|
+
プログレスバー.Value = value_num;
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
```
|
330
|
+
|
331
|
+
```XAML
|
332
|
+
|
333
|
+
<Window x:Class="PSDConverter4.MainWindow"
|
334
|
+
|
335
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
336
|
+
|
337
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
338
|
+
|
339
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
340
|
+
|
341
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
342
|
+
|
343
|
+
xmlns:local="clr-namespace:PSDConverter4"
|
344
|
+
|
345
|
+
mc:Ignorable="d"
|
346
|
+
|
347
|
+
Title="PSD" Height="170" Width="250"
|
348
|
+
|
349
|
+
Background="Silver"
|
350
|
+
|
351
|
+
ResizeMode="NoResize">
|
352
|
+
|
353
|
+
<Grid>
|
354
|
+
|
355
|
+
<Label x:Name="読み込みファイル名" Content="File Path" HorizontalAlignment="Left" Margin="10,16,0,0" VerticalAlignment="Top" Width="61"/>
|
356
|
+
|
357
|
+
<TextBox x:Name="パス" HorizontalAlignment="Left" Height="23" Margin="71,19,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="120"/>
|
358
|
+
|
359
|
+
<Button x:Name="ダイアログ" Content="・・・" HorizontalAlignment="Left" Margin="201,19,0,0" VerticalAlignment="Top" Width="22" RenderTransformOrigin="1.205,0.45" Height="23" Click="Clicked_Dialog"/>
|
360
|
+
|
361
|
+
<Button x:Name="スタート" Content="START" HorizontalAlignment="Left" Margin="10,92,0,0" VerticalAlignment="Top" Width="213" Height="24" Click="Clicked_Start"/>
|
362
|
+
|
363
|
+
<ProgressBar Name="プログレスバー" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,58,0,0" Height="16" Width="213" Minimum="0" Maximum="100" IsIndeterminate="False"/>
|
364
|
+
|
365
|
+
</Grid>
|
366
|
+
|
367
|
+
</Window>
|
368
|
+
|
369
|
+
```
|