コード例 #1
0
 private void TegakiCanvas_SelectionChanged(object sender, EventArgs e)
 {
     if (TegakiCanvas.GetSelectedElements().Count + TegakiCanvas.GetSelectedStrokes().Count != 0)
     {
         TegakiCanvas.ContextMenu = EditMenu;
     }
     else
     {
         TegakiCanvas.ContextMenu = NormalMenu;
     }
 }
コード例 #2
0
        //削除ボタン
        void Remove_Click(object sender, RoutedEventArgs e)
        {
            List <UIElement> UIEL = new List <UIElement>();
            List <Stroke>    SL   = TegakiCanvas.GetSelectedStrokes().ToList();

            foreach (UIElement UIE in TegakiCanvas.GetSelectedElements())
            {
                UIEL.Add(UIE);
            }
            foreach (UIElement UIE in UIEL)
            {
                TegakiCanvas.Children.Remove(UIE);
            }
            foreach (Stroke S in SL)
            {
                TegakiCanvas.Strokes.Remove(S);
            }
            TegakiCanvas.ContextMenu = NormalMenu;
        }
コード例 #3
0
        private void OCRText(int mode = 0)
        {
            StrokeCollection sc;

            switch (mode)
            {
            case 0:
                sc = OCRCanvas.Strokes;
                break;

            case 1:
                sc = TegakiCanvas.GetSelectedStrokes();
                break;

            default:
                return;
            }

            ia = new InkAnalyzer();
            if (sc.Count == 0)
            {
                return;
            }
            CustomRecognizerNode node;
            double x, y;
            int    height;

            getStrokeZahyo(sc, out x, out y, out height);

            // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット
            if (EngineList.SelectedItem != null)
            {
                node = ia.CreateCustomRecognizer((Guid)EngineList.SelectedValue);
                ia.AddStrokesToCustomRecognizer(sc, node);
            }
            else
            {
                ia.AddStrokes(sc);
            }
            ia.SetStrokesType(sc, StrokeType.Writing);

            // 文字を解析
            ia.Analyze();

            //罫線にピタッとなるようにする
            y = ((int)((y + lineMargine / 2) / lineMargine) * lineMargine) + 1 * (int)((y + lineMargine / 2) / lineMargine);

            height = (int)((height + lineMargine / 2) / lineMargine) * lineMargine;
            if (height >= 8)
            {
                TextBlock tb = new TextBlock()
                {
                    Text = ia.GetRecognizedString(), FontSize = height - 8, VerticalAlignment = System.Windows.VerticalAlignment.Top, LineStackingStrategy = LineStackingStrategy.BlockLineHeight, LineHeight = height
                };
                //noteRoot.Children.Add(tb);
                TegakiCanvas.Children.Add(tb);
                InkCanvas.SetLeft(tb, x);
                InkCanvas.SetTop(tb, y);
            }
            //textBox1.Text += ia.GetRecognizedString();
            switch (mode)
            {
            case 0:
                OCRCanvas.Strokes.Clear();
                break;

            case 1:
                foreach (Stroke s in sc)
                {
                    TegakiCanvas.Strokes.Remove(s);
                }
                break;
            }

            /*
             * // その他の候補を表示する
             * AnalysisAlternateCollection alternates = theInkAnalyzer.GetAlternates();
             * foreach (var alternate in alternates)
             * MessageBox.Show(alternate.RecognizedString);
             */
        }