示例#1
0
        public override void SerializePoints(Stream stream, int numPoints)
        {
            IFormatter formatter = new BinaryFormatter();

            // Calculate the number of strokes to serialize
            int index     = this.myInk.Strokes.Count;
            int countLeft = numPoints;

            while (countLeft > 0 && index > 0)
            {
                index--;
                countLeft -= this.myInk.Strokes[index].GetPoints().Length;
            }
            // Index is now -1 or the first stroke to send.
            if (index < 0)
            {
                index = 0;
            }

            if (countLeft < 0)
            {
                countLeft += this.myInk.Strokes[index].GetPoints().Length;
            }

            // If there is a partial stroke, serialize it specially
            if (countLeft > 0)
            {
                formatter.Serialize(stream, true);                 // Flag that there is a partial stroke.
            }
            else
            {
                formatter.Serialize(stream, false);                 // Flag that there is no partial stroke.
            }
            // Serialize just a zero (length) for an empty scribble.
            if (this.myInk.Strokes.Count - index == 0)
            {
                formatter.Serialize(stream, 0);
            }
            else
            {
                // Serialize all remaining strokes completely
                Ink.Ink ink = new Ink.Ink();
                int[]   ids = new int[this.myInk.Strokes.Count - index];
                for (int i = index; i < this.myInk.Strokes.Count; i++)
                {
                    ids[i - index] = this.myInk.Strokes[i].Id;
                }
                // Note: AddStrokesAtRectangle is used since the documentation for AddStrokes
                // states that the strokes must *already* be in the ink object (so, it's only
                // used for updating custom strokes collections??).
                Ink.Strokes strokes = this.myInk.CreateStrokes(ids);
                ink.AddStrokesAtRectangle(strokes, strokes.GetBoundingBox());
                byte[] inkBytes = ink.Save();
                formatter.Serialize(stream, inkBytes.Length);
                stream.Write(inkBytes, 0, inkBytes.Length);
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="document"></param>
        /// <param name="strokes"></param>
        /// <param name="label"></param>
        public void createShapeWithLabel(MakeXML document, Microsoft.Ink.Strokes strokes, string label)
        {
            //Create the new shape we will add
            Shape toAdd = new Shape(System.Guid.NewGuid().ToString(), label, "", label);

            //Extra information for the shape
            toAdd.Source = "LabelerSession" + this.GetHashCode().ToString();
            toAdd.Width  = strokes.GetBoundingBox().Width.ToString();
            toAdd.Height = strokes.GetBoundingBox().Height.ToString();
            toAdd.X      = strokes.GetBoundingBox().X.ToString();
            toAdd.Y      = strokes.GetBoundingBox().Y.ToString();


            ulong currentTime;
            ulong bestTime = 0;

            foreach (Microsoft.Ink.Stroke stroke in strokes)
            {
                int id = stroke.Id;

                Stroke s = (Stroke)idToCStroke[id];

                Stroke.Arg arg = new Stroke.Arg(s.Type, s.Id);

                toAdd.Args.Add(arg);

                currentTime = Convert.ToUInt64(s.Time);
                if (currentTime > bestTime)
                {
                    bestTime = currentTime;
                }
            }

            toAdd.Time = bestTime.ToString();

            document.addShape(toAdd);
        }