Пример #1
0
        // This function will load XML into the ink object.
        // It will repopulate the text boxes using the data stored in the XML.
        private void LoadXML(Stream s)
        {
            // This object will encode our byte data to a UTF8 string
            UTF8Encoding utf8 = new UTF8Encoding();

            XmlDocument xd = new XmlDocument();
            XmlNodeList nodes;

            Microsoft.Ink.Ink loadedInk = new Microsoft.Ink.Ink();

            // Load the XML data into an XMLDocument object
            xd.Load(s);

            // Get the data in the ink node
            nodes = xd.GetElementsByTagName("Ink");

            // load the ink into a new ink object
            // once an ink object has been "dirtied" it can never load ink again
            if (0 != nodes.Count)
            {
                loadedInk.Load(utf8.GetBytes(nodes[0].InnerXml));
            }

            // temporarily disable the ink collector and swap ink objects
            // We checked the InkCollector.CollectingInk property to verify
            // the user has stopped inking. Otherwise, Enabled will throw
            // InvalidOperationException.
            ic.Enabled = false;

            ic.Ink     = loadedInk;
            ic.Enabled = true;

            // Repaint the inkable region
            Signature.Invalidate();

            // Get the data in the FirstName node
            nodes = xd.GetElementsByTagName("FirstName");
            if (0 != nodes.Count)
            {
                FirstNameBox.Text = nodes[0].InnerXml;
            }
            else
            {
                FirstNameBox.Text = String.Empty;
            }

            // Get the data in the LastName node
            nodes = xd.GetElementsByTagName("LastName");
            if (0 != nodes.Count)
            {
                LastNameBox.Text = nodes[0].InnerXml;
            }
            else
            {
                LastNameBox.Text = String.Empty;
            }
        }
Пример #2
0
        // This function will load ISF into the ink object.
        // It will also pull the data stored in the object's extended properties and
        // repopulate the text boxes.
        private void LoadISF(Stream s)
        {
            Microsoft.Ink.Ink loadedInk = new Microsoft.Ink.Ink();
            byte[]            isfBytes  = new byte[s.Length];

            // read in the ISF
            s.Read(isfBytes, 0, (int)s.Length);

            // load the ink into a new ink object
            // once an ink object has been "dirtied" it can never load ink again
            loadedInk.Load(isfBytes);

            // temporarily disable the ink collector and swap ink objects
            // We checked the InkCollector.CollectingInk property to verify
            // the user has stopped inking. Otherwise, Enabled will throw
            // InvalidOperationException.
            ic.Enabled = false;

            ic.Ink     = loadedInk;
            ic.Enabled = true;

            // Repaint the inkable region
            Signature.Invalidate();

            ExtendedProperties inkProperties = ic.Ink.ExtendedProperties;

            // Get the raw data out of this stroke's extended
            // properties list, using our previously defined
            // Guid as a key to the extended property we want.
            // Since the save method stored the first and last
            // name information as extended properties, we can
            // remove this information now that the load is complete.
            if (inkProperties.DoesPropertyExist(FirstName))
            {
                FirstNameBox.Text = (String)inkProperties[FirstName].Data;
                inkProperties.Remove(FirstName);
            }
            else
            {
                FirstNameBox.Text = String.Empty;
            }

            if (inkProperties.DoesPropertyExist(LastName))
            {
                LastNameBox.Text = (String)inkProperties[LastName].Data;
                inkProperties.Remove(LastName);
            }
            else
            {
                LastNameBox.Text = String.Empty;
            }
        }
        private void save_with_background_Button_Copy_Click(object sender, RoutedEventArgs e)
        {
            StrokeCollection sc = InkCanvas.Strokes;

            byte[] inkData = null;
            using (MemoryStream inkMemStream = new MemoryStream())
            {
                sc.Save(inkMemStream);
                inkData = inkMemStream.ToArray();
            }
            byte[] gifData = null;
            using (Microsoft.Ink.Ink ink = new Microsoft.Ink.Ink())
            {
                ink.Load(inkData);
                gifData = ink.Save(PersistenceFormat.Gif);
            }
            File.WriteAllBytes("c://strokes.gif", gifData);
        }
Пример #4
0
        private void theInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            MemoryStream ms = new MemoryStream();

            theInkCanvas.Strokes.Save(ms);//canvas为InkCanvas
            Microsoft.Ink.Ink ink = new Microsoft.Ink.Ink();
            ink.Load(ms.ToArray());
            string[] resultArray = null;//存放识别的结果
            using (Microsoft.Ink.RecognizerContext myRecoContext = new Microsoft.Ink.RecognizerContext())
            {
                Microsoft.Ink.RecognitionStatus status;//识别的结果状态,可用于判断是否识别成功
                Microsoft.Ink.RecognitionResult recoResult;
                myRecoContext.Strokes = ink.Strokes;
                try
                {
                    recoResult = myRecoContext.Recognize(out status);

                    if (status == RecognitionStatus.NoError)
                    {
                        List <StrokeWord> slist = new List <StrokeWord>();
                        Microsoft.Ink.RecognitionAlternates als = recoResult.GetAlternatesFromSelection();
                        int resultCount = als.Count;
                        resultArray = new string[resultCount];
                        for (int i = 0; i < resultCount; i++)
                        {
                            StrokeWord sw = new StrokeWord();
                            sw.StrokeName = als[i].ToString();
                            slist.Add(sw);
                            //resultArray[i] = als[i].ToString();//多余
                        }

                        this.StrokeWordList = new List <StrokeWord>();
                        this.StrokeWordList = slist;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }
        // This function will load XML into the ink object.
        // It will repopulate the text boxes using the data stored in the XML.
        private void LoadXML(Stream s)
        {
            // This object will encode our byte data to a UTF8 string
            UTF8Encoding utf8 = new UTF8Encoding();

            XmlDocument xd = new XmlDocument();
            XmlNodeList nodes;
            Microsoft.Ink.Ink loadedInk = new Microsoft.Ink.Ink();

            // Load the XML data into an XMLDocument object
            xd.Load(s);

            // Get the data in the ink node
            nodes = xd.GetElementsByTagName("Ink");

            // load the ink into a new ink object
            // once an ink object has been "dirtied" it can never load ink again
            if (0 != nodes.Count)
            {
                loadedInk.Load(utf8.GetBytes(nodes[0].InnerXml));
            }

            // temporarily disable the ink collector and swap ink objects
            // We checked the InkCollector.CollectingInk property to verify
            // the user has stopped inking. Otherwise, Enabled will throw
            // InvalidOperationException.
            ic.Enabled = false;

            ic.Ink = loadedInk;
            ic.Enabled = true;

            // Repaint the inkable region
            Signature.Invalidate();

            // Get the data in the FirstName node
            nodes = xd.GetElementsByTagName("FirstName");
            if (0 != nodes.Count)
            {
                FirstNameBox.Text = nodes[0].InnerXml;
            }
            else
            {
                FirstNameBox.Text = String.Empty;
            }

            // Get the data in the LastName node
            nodes = xd.GetElementsByTagName("LastName");
            if (0 != nodes.Count)
            {
                LastNameBox.Text = nodes[0].InnerXml;
            }
            else
            {
                LastNameBox.Text = String.Empty;
            }
        }
        // This function will load ISF into the ink object.
        // It will also pull the data stored in the object's extended properties and
        // repopulate the text boxes.
        private void LoadISF(Stream s)
        {
            Microsoft.Ink.Ink loadedInk = new Microsoft.Ink.Ink();
            byte[] isfBytes = new byte[s.Length];

            // read in the ISF
            s.Read(isfBytes, 0, (int) s.Length);

            // load the ink into a new ink object
            // once an ink object has been "dirtied" it can never load ink again
            loadedInk.Load(isfBytes);

            // temporarily disable the ink collector and swap ink objects
            // We checked the InkCollector.CollectingInk property to verify
            // the user has stopped inking. Otherwise, Enabled will throw
            // InvalidOperationException.
            ic.Enabled = false;

            ic.Ink = loadedInk;
            ic.Enabled = true;

            // Repaint the inkable region
            Signature.Invalidate();

            ExtendedProperties inkProperties = ic.Ink.ExtendedProperties;

            // Get the raw data out of this stroke's extended
            // properties list, using our previously defined
            // Guid as a key to the extended property we want.
            // Since the save method stored the first and last
            // name information as extended properties, we can
            // remove this information now that the load is complete.
            if (inkProperties.DoesPropertyExist(FirstName))
            {
                FirstNameBox.Text = (String) inkProperties[FirstName].Data;
                inkProperties.Remove(FirstName);
            }
            else
            {
                FirstNameBox.Text = String.Empty;
            }

            if (inkProperties.DoesPropertyExist(LastName))
            {
                LastNameBox.Text = (String) inkProperties[LastName].Data;
                inkProperties.Remove(LastName);
            }
            else
            {
                LastNameBox.Text = String.Empty;
            }
        }