Esempio n. 1
0
 public RTDrawStroke(Microsoft.Ink.Ink ink, Guid guid, bool strokeFinished, Guid deckGuid, int slideIndex)
 {
     this.ink            = ink;
     this.guid           = guid;
     this.strokeFinished = strokeFinished;
     this.deckGuid       = deckGuid;
     this.slideIndex     = slideIndex;
 }
        // 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;
            }
        }
Esempio n. 3
0
 protected RTDrawStroke(SerializationInfo info, StreamingContext context)
 {
     this.ink = new Microsoft.Ink.Ink();
     this.ink.Load((byte[])info.GetValue("ink", typeof(byte[])));
     this.guid           = new Guid(info.GetString("guid"));
     this.strokeFinished = info.GetBoolean("strokeFinished");
     this.deckGuid       = new Guid(info.GetString("deckGuid"));
     this.slideIndex     = info.GetInt32("slideIndex");
 }
Esempio n. 4
0
        public override void Execute()
        {
            this.fragPanel.StrokeToCorners = this.clearedStrokeToCorners;

            this.inkForDeletedStrokes = new Ink();
            this.inkForDeletedStrokes.AddStrokesAtRectangle(this.overlayInk.Ink.Strokes,
                                                            this.overlayInk.Ink.Strokes.GetBoundingBox());

            this.overlayInk.Ink.DeleteStrokes();

            this.fragPanel.SketchInk.Refresh();
        }
        // 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;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Converts a Sketch shape into a collection of Microsoft.Ink strokes.
        /// </summary>
        /// <param name="shape">The shape to convert</param>
        /// <returns>The desired ink strokes</returns>
        public Microsoft.Ink.Strokes convertToInk(Sketch.Shape shape)
        {
            // Create a collection of strokes
            Microsoft.Ink.Ink     ink        = new Microsoft.Ink.Ink();
            Microsoft.Ink.Strokes inkStrokes = ink.CreateStrokes();

            Sketch.Substroke[] sketchStrokes = shape.Substrokes;

            // Add the substrokes of our format to the strokes collection.
            foreach (Sketch.Substroke sub in sketchStrokes)
            {
                inkStrokes.Add(convertToInk(sub, ink));
            }

            return(inkStrokes);
        }
Esempio n. 7
0
        /// <summary>
        /// Converts a Sketch substroke into a Microsoft.Ink stroke.
        /// </summary>
        /// <param name="substroke">The Sketch substroke to convert</param>
        /// <param name="ink">A Microsoft.Ink Ink object</param>
        /// <returns>The desired ink stroke</returns>
        private Microsoft.Ink.Stroke convertToInk(
            Sketch.Substroke substroke,
            Microsoft.Ink.Ink ink)
        {
            int pointsCount = substroke.Points.Length;

            System.Drawing.Point[] inkPoints = new System.Drawing.Point[pointsCount];

            // Convert the Sketch point format to Microsoft point format
            for (int i = 0; i < pointsCount; i++)
            {
                inkPoints[i] = new System.Drawing.Point(
                    (int)(substroke.Points[i].X),
                    (int)(substroke.Points[i].Y));
            }

            return(ink.CreateStroke(inkPoints));
        }
        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);
        }
Esempio n. 9
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;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Creates the strokes in this xml document as C# strokes and adds them to the corresponding Ink object.
        /// We cannot create new strokes with the same Id's that we have in the MIT XML format, so instead we
        /// return a hash table mapping the created strokes' Ids (1, 2, ... , n) with the strokes.
        /// </summary>
        ///
        /// <returns>A Hashtable that holds links back to the Converter strokes</returns>
        public Hashtable getIdToCStroke(Sketch sketch, Microsoft.Ink.Ink inkObject)
        {
            ArrayList strokes = sketch.Shapes;
            ArrayList points  = sketch.Points;

            Hashtable retTable = new Hashtable();

            // Create a hashtable between points and IDs for easy access
            Hashtable pointTable = sketch.IdToPoint;

            // Now create the C# strokes
            foreach (Shape s in strokes)
            {
                Stroke st = new Stroke(s);

                // first check to be sure it's a matching shape
                if (st.matches(Stroke.ShapeType.STROKE))
                {
                    // Get all of the stroke's points
                    ArrayList pts = s.getArgIds();

                    System.Drawing.Point[] xypts = new System.Drawing.Point[pts.Count];
                    //int[] pressureData = new int[pts.Count];
                    //int[] timerData    = new int[pts.Count];

                    int index = 0;
                    //Console.WriteLine( "loading stroke...");
                    foreach (string id in pts)
                    {
                        Point p = (Point)pointTable[id];
                        st.Points.Add(p);
                        st.Args.Add(new Stroke.Arg("Point", p.Id));

                        // Just get the x and the y, ignore the rest
                        int x = Convert.ToInt32(p.X);
                        int y = Convert.ToInt32(p.Y);

                        //Console.WriteLine( "[x: {0}, y: {1}]", x, y );
                        xypts[index] = new System.Drawing.Point(x, y);

                        //pressureData[index] = (int)p.Pressure;
                        //timerData[index]    = (int)p.Time;

                        ++index;
                    }

                    Microsoft.Ink.Stroke newStroke = inkObject.CreateStroke(xypts);

                    /*
                     * // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/TimeStampsBestPractices.asp
                     * // mike used: 8fe68ce5-c39c-4f52-afbb-65344e8e49ff
                     * newstroke.ExtendedProperties.Add(new Guid("8A54CF58-97E6-4fc5-8F06-F8BAD2E19B22"), (long)s.Time);
                     *
                     * // newstroke.SetPacketValuesByProperty(Microsoft.Ink.PacketProperty.NormalPressure, pressureData);
                     * newstroke.SetPacketValuesByProperty(Microsoft.Ink.PacketProperty.TimerTick, timerData);
                     */

                    retTable.Add(newStroke.Id, st);
                }
            }

            return(retTable);
        }
        /// <summary>
        /// Stroke event handler fired when a stroke is just finished.
        /// </summary>
        /// <remarks>Notice that even if we use a InkOverlay object and not a InkCollector
        /// object, the second input parameter is of type InkCollectorStrokeEventArgs</remarks>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments (type InkCollectorStrokeEventArgs)</param>
        private void inkOverlay_Stroke(object sender, InkCollectorStrokeEventArgs e)
        {
            if (e.Stroke.DrawingAttributes.Transparency != 255)
            {
                Log("A stroke has been drawn!");

                // Resize the stroke before sending
                Log("Resize the stroke,");
                DisplaySizeInfo();
                Microsoft.Ink.Strokes strokes = inkOverlay.Ink.CreateStrokes();
                strokes.Add(e.Stroke);
                Microsoft.Ink.Ink newInk = new Microsoft.Ink.Ink();
                newInk.AddStrokesAtRectangle(strokes, strokes.GetBoundingBox());
                Microsoft.Ink.Stroke copiedStroke = newInk.Strokes[0];
                // Note: rtDocument.Resources.Pages[pageShowing].Image.Width cannot be 
                // used here because it's 5760 when open a PPT document
                // Ditto for rtDocument.Resources.Pages[pageShowing].Image.Height, 
                // the value is 4320
                float ratioWidthSend = (float)constWidthPageSend/(float)pbRTDoc.Width;
                float ratioHeightSend = (float)constHeightPageSend/(float)pbRTDoc.Height;
                Log(string.Format(CultureInfo.CurrentCulture, "RatioWidthSend={0},  RatioHeightSend={1}, ", 
                    ratioWidthSend.ToString(CultureInfo.InvariantCulture), 
                    ratioHeightSend.ToString(CultureInfo.InvariantCulture)));
                copiedStroke.Scale(ratioWidthSend, ratioHeightSend);

                // Send the resized stroke
                Log("Send a resized stroke,");
                rtDocumentHelper.SendStrokeAdd(copiedStroke);

                // Copy the guid in the extendend property generated inside copieStroke 
                // by rtDocumentHelper.BeginSendStrokeAdd in the extended property of the
                // local stroke
                // Note: it is very important to do that because when the user
                // delete a stroke, the stroke guid of the local and remote
                // stroke must match (copieStroke is the stroke that is sent,
                // e.Stroke is the local stroke)
                e.Stroke.ExtendedProperties.Add(RTStroke.ExtendedPropertyStrokeIdentifier, 
                    copiedStroke.ExtendedProperties[RTStroke.ExtendedPropertyStrokeIdentifier].Data);
            }
        }