|
@@ -1,4 +1,5 @@
|
|
|
-using System;
|
|
|
+using ImageMagick;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
@@ -26,10 +27,6 @@ namespace MovieBarcodeGenerator {
|
|
|
|
|
|
public static void Generate(string inputFile, string outputFile, int height, int barWidth, int iterations) {
|
|
|
log.Debug("Generate()");
|
|
|
- if (!Directory.Exists(imagickPath)) {
|
|
|
- log.ErrorFormat("ImageMagick was not found at '{0}'.", imagickPath);
|
|
|
- throw new Exception("ImageMagick was not found.");
|
|
|
- }
|
|
|
if (File.Exists(outputFile)) {
|
|
|
log.InfoFormat("Output file '{0}' exists. Deleting file.", outputFile);
|
|
|
File.Delete(outputFile);
|
|
@@ -49,13 +46,16 @@ namespace MovieBarcodeGenerator {
|
|
|
|
|
|
log.Debug("Scrunching PNGs together.");
|
|
|
// use ImageMagick to crush the generated PNGs together
|
|
|
- Process p = new Process();
|
|
|
- p.StartInfo.FileName = Path.Combine(imagickPath, "convert.exe");
|
|
|
- p.StartInfo.WorkingDirectory = Path.GetDirectoryName(outputFile);
|
|
|
- p.StartInfo.Arguments = String.Format("out_*.png +append \"{0}\"", outputFile);
|
|
|
- p.StartInfo.UseShellExecute = false;
|
|
|
- p.Start();
|
|
|
- p.WaitForExit();
|
|
|
+ using (MagickImageCollection images = new MagickImageCollection()) {
|
|
|
+ foreach (var file in Directory.GetFiles(Path.GetDirectoryName(outputFile), "out_???.png")) {
|
|
|
+ images.Add(new MagickImage(file));
|
|
|
+ }
|
|
|
+ // create a strip from all those images
|
|
|
+ using (IMagickImage result = images.AppendHorizontally()) {
|
|
|
+ // Save the result
|
|
|
+ result.Write(outputFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
log.Debug("Deleting temporary work files.");
|
|
|
// clean up the work files
|