RKrom 4de75cdb69 Cleanup of using statements
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2149 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
2012-10-17 12:21:12 +00:00

55 lines
1.5 KiB
C#

using System;
using System.IO;
using Greenshot.Interop;
using GreenshotOCR;
namespace GreenshotOCRCommand {
public class Program {
private const string USAGE = "<-c> | <path to image.bmp> [language] [orientimage] [straightenImage]";
public static int Main(string[] args) {
// to test
//args = new string[] { @"C:\localdata\test.bmp"};
if (args.Length == 0) {
Console.WriteLine(USAGE);
return -1;
}
string filename = args[0];
ModiLanguage language = ModiLanguage.ENGLISH;
if (args.Length >= 2) {
language = (ModiLanguage)Enum.Parse(typeof(ModiLanguage), args[1]);
}
bool orientimage = true;
if (args.Length >= 3) {
orientimage = bool.Parse(args[2]);
}
bool straightenImage = true;
if (args.Length >= 4) {
straightenImage = bool.Parse(args[3]);
}
try {
if (File.Exists(filename) || "-c".Equals(filename)) {
using (ModiDocu modiDocument = COMWrapper.GetOrCreateInstance<ModiDocu>()) {
if (modiDocument == null) {
Console.WriteLine("MODI not installed");
return -2;
}
if ("-c".Equals(filename)) {
return 0;
}
modiDocument.Create(filename);
modiDocument.OCR(language, orientimage, straightenImage);
IImage modiImage = modiDocument.Images[0];
ILayout layout = modiImage.Layout;
Console.WriteLine(layout.Text);
modiDocument.Close(false);
return 0;
}
}
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
return -1;
}
}
}