找传奇、传世资源到传世资源站!

wpf手写识别汉字

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

用于手写识别汉字等wpf手写识别汉字 C#语言基础-第1张 public partial class InkTablet : INotifyPropertyChanged
    {
        public InkTablet()
        {
            InitializeComponent();
            theInkCanvas.MouseUp = OnInkCanvasMouseUp;
        }

        private Visibility _isTabletVisible;

        public Visibility IsTabletVisible
        {
            get
            {
                return this._isTabletVisible;
            }
            set
            {
                if (value != this._isTabletVisible)
                {
                    this._isTabletVisible = value;
                    this.NotifyPropertyChanged("IsTabletVisible");
                }
            }
        }

        private ICommand _newCommand;

        public ICommand NewCommand
        {
            get
            {
                return this._newCommand ?? (this._newCommand = new DelegateCommand(this.OnNewClick));
            }
        }

        private void OnNewClick()
        {
            this.theInkCanvas.Strokes.Clear();
            this.StrokeWordList = new List<StrokeWord>();
        }

        private IList<StrokeWord> _strokeWordList;

        public IList<StrokeWord> StrokeWordList
        {
            get
            {
                return this._strokeWordList;
            }
            set
            {
                this._strokeWordList = value;
                this.NotifyPropertyChanged("StrokeWordList");
            }
        }

        private void OnInkCanvasMouseUp(object sender, MouseButtonEventArgs e)
        {
            InkAnalyzer theInkAnalyzer = new InkAnalyzer();
            AnalysisHintNode hint = theInkAnalyzer.CreateAnalysisHint();
            hint.Guide.Columns = 1;
            hint.Guide.Rows = 1;
            hint.WordMode = true;
            hint.TopInkBreaksOnly = true;

            hint.Location.MakeInfinite();
            theInkAnalyzer.RemoveStrokes(theInkCanvas.Strokes);
            theInkAnalyzer.AddStrokes(theInkCanvas.Strokes);
            theInkAnalyzer.SetStrokesLanguageId(theInkCanvas.Strokes, 0x0804);
            theInkAnalyzer.SetStrokesType(theInkCanvas.Strokes, StrokeType.Writing);
            AnalysisStatus status = theInkAnalyzer.Analyze();

            if (status.Successful)
            {
                List<StrokeWord> slist = new List<StrokeWord>();
                //textBox1.Text = theInkAnalyzer.GetRecognizedString();
                for (int i = 0; i < theInkAnalyzer.GetAlternates().Count; i )
                {
                    string resultStr = theInkAnalyzer.GetAlternates()[i].RecognizedString;
                    if (resultStr.Length == 1)
                    {
                        StrokeWord sw = new StrokeWord();
                        sw.StrokeName = resultStr;
                        slist.Add(sw);
                    }
                }

                this.StrokeWordList = slist;
            }
            else
            {
                MessageBox.Show("识别失败");
            }
        }

        private string _nameStr;

        public string NameStr
        {
            get
            {
                return this._nameStr;
            }
            set
            {
                if (value != this.NameStr)
                {
                    this._nameStr = value;
                    this.NotifyPropertyChanged("NameStr");
                }
            }
        }

        private ICommand _itemCommand;

        public ICommand ItemCommand
        {
            get
            {
                return this._itemCommand ?? (this._itemCommand = new DelegateCommand<Button>(this.OnItemClick));
            }
        }

        private void OnItemClick(Button btn)
        {
            this.NameStr = btn.Tag.ToString();
            this.OnNewClick();
        }

        private ICommand _sureCommand;

        public ICommand SureCommand
        {
            get
            {
                return this._sureCommand ?? (this._sureCommand = new DelegateCommand(this.OnSureClick));
            }
        }

        private void OnSureClick()
        {
            this.IsTabletVisible = Visibility.Hidden;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string property)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复