Esempio n. 1
0
        /// <summary>
        /// Do an action.
        /// </summary>
        /// <param name='action'>
        /// Action.
        /// </param>
        public void Do(Act action)
        {
            if (!Should(action))
            {
                return;
            }

            var app = this;

            switch (action)
            {
            case Act.AnalyzeHorizontal: AnalyzeAction.AnalyzeHorizontal(app); return;

            case Act.AnalyzeVertical: AnalyzeAction.AnalyzeVertical(app); return;

            case Act.AnalyzeIslands: AnalyzeAction.AnalyzeIslands(app); return;

            case Act.Analyze: AnalyzeAction.Analyze(app); return;

            case Act.Clean: CleanAction.Clean(app); return;

            case Act.RemoveBackground: RemoveBackgroundAction.RemoveBackground(app); return;

            case Act.CopyToClipboard: CopyToClipboardAction.CopyToClipboard(app); return;

            case Act.RefreshIslandsOutputAction: RefreshIslandsOutputAction.Refresh(app); return;

            case Act.Process: ProcessAction.Process(app); return;
            }

#if DEBUG
            throw new NotImplementedException(action.ToString());
#endif
        }
        public static void RemoveBackground(App app)
        {
            if (app.Filename == null)
            {
                return;
            }
            if (app.Image == null)
            {
                return;
            }

            var img = app.Image;

            if (img == null)
            {
                return;
            }

            app.Task = "Remove background color";

            var helper = new RemoveBackgroundColorHelper();

            helper.Step1_SetImage(img);
            helper.Step2_SetDetectByFirstRow();
            helper.Step3_RemoveBackground();

            app.ErrorMessage = null;
            app.UI(UI.ErrorMessage);
            try {
                img.Save(app.Filename, "png");
            } catch (Exception ex) {
                app.ErrorMessage = ex.Message;
                app.UI(UI.ErrorMessage);
                Console.WriteLine(ex.ToString());
            }

            app.UI(UI.CompletedTask);

            AnalyzeAction.Analyze(app);
        }