コード例 #1
0
        //导入草图方法
        public void LoadSketch(List <System.Drawing.Bitmap> BitmapList, List <Point> points, int width, int height)
        {
            List <BitmapImage> bmpList = new List <BitmapImage>();
            int i = 0;

            foreach (System.Drawing.Bitmap bit in BitmapList)
            {
                bmpList.Add(WPFInk.tool.ConvertClass.getInstance().BitmapToBitmapImage(bit));
            }



            int    j;
            string pathName = GlobalValues.FilesPath + "//WPFink/0.bmp";

            BitmapList[0].Save(pathName);
            MyImage preMyImage = new MyImage(pathName);
            MyImage MyImage0   = preMyImage;

            preMyImage.Width    = width;
            preMyImage.Height   = height;
            preMyImage.Left     = points[0].X;
            preMyImage.Top      = points[0].Y;
            preMyImage.PathName = pathName;
            preMyImage.setLocation((int)points[0].X, (int)points[0].Y);
            InkConstants.AddBound(preMyImage);

            AddImageCommand cmd = new AddImageCommand(InkCollector, preMyImage);

            cmd.execute();
            ImageConnector connector = null;

            for (i = 0; i < bmpList.Count - 1; i++)
            {
                j        = i + 1;
                pathName = GlobalValues.FilesPath + "//WPFink/" + j + ".bmp";

                BitmapList[j].Save(pathName);
                MyImage newimage = new MyImage(pathName);
                newimage.Width  = width;
                newimage.Height = height;
                newimage.setLocation((int)points[j].X, (int)points[j].Y);
                newimage.Left     = points[j].X;
                newimage.Top      = points[j].Y;
                newimage.PathName = pathName;
                InkConstants.AddBound(newimage);
                AddImageCommand cmd2 = new AddImageCommand(InkCollector, newimage);
                cmd2.execute();
                connector  = new ImageConnector(preMyImage, newimage);
                preMyImage = newimage;
                MyStroke myStroke = connector.MYSTROKE;
                myStroke.Stroke.DrawingAttributes.Width  = 4;
                myStroke.Stroke.DrawingAttributes.Height = 4;
                myStroke.IsSketchConnector = true;
                Command sc = new AddStrokeCommand(InkCollector, myStroke);
                sc.execute();
            }
        }
コード例 #2
0
        public override void _presenter_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (_startpoint != null)
            {
                if (_inkCanvas.Strokes.Count - 1 > _inkCollector._sketch.MyStrokes.Count)
                {
                    _inkCollector._sketch.MyStrokes.Clear();
                    foreach (Stroke stroke in _inkCanvas.Strokes)
                    {
                        _mystroke           = new MyStroke(stroke);
                        _mystroke.StartTime = _starttime;
                        _mystroke.EndTime   = MyTimer.getInstance().getTime();

                        Command addStrokeCommand = new AddStrokeCommand(_inkCollector, _mystroke);
                        _inkCollector.CommandStack.Push(addStrokeCommand);
                        addStrokeCommand.execute();
                    }
                }
                else
                {
                    //Point current = e.GetPosition(_inkCanvas);
                    //Console.WriteLine("up:"+current.X + "," + current.Y);
                    if (_inkCanvas.Strokes.Count > 0)
                    {
                        Stroke lastStroke = _inkCanvas.Strokes.Last();

                        _mystroke           = new MyStroke(lastStroke);
                        _mystroke.StartTime = _starttime;
                        _mystroke.EndTime   = MyTimer.getInstance().getTime();

                        Command addStrokeCommand = new AddStrokeCommand(_inkCollector, _mystroke);
                        _inkCollector.CommandStack.Push(addStrokeCommand);
                        addStrokeCommand.execute();
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 将stroke以点迹的模式擦除,拆分成两个stroke
        /// </summary>
        /// <param name="stroke">被擦除的stroke</param>
        /// <param name="pointErasePoints">擦除的点</param>
        void ProcessPointErase(Stroke stroke, Point pointErasePoint)
        {
            if (stroke.StylusPoints.Count > 1)
            {
                Stroke hitTestStroke;
                StylusPointCollection splitStrokePoints1 = new StylusPointCollection();
                StylusPointCollection splitStrokePoints2 = new StylusPointCollection();

                StylusPointCollection spc = new StylusPointCollection();
                foreach (StylusPoint point in stroke.StylusPoints)
                {
                    spc.Add(point);
                }
                hitTestStroke = new Stroke(spc);
                hitTestStroke.DrawingAttributes = stroke.DrawingAttributes;

                while (true)
                {
                    if (hitTestStroke.StylusPoints.Count > 0)
                    {
                        if (hitTestStroke.StylusPoints.Count > 1)
                        {
                            StylusPoint sp = hitTestStroke.StylusPoints[hitTestStroke.StylusPoints.Count - 1];
                            hitTestStroke.StylusPoints.RemoveAt(hitTestStroke.StylusPoints.Count - 1);
                            if (!hitTestStroke.HitTest(pointErasePoint, 3))
                            {
                                break;
                            }
                            splitStrokePoints2.Add(sp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }


                StylusPointCollection spc2 = new StylusPointCollection();
                foreach (StylusPoint point in stroke.StylusPoints)
                {
                    spc2.Add(point);
                }
                hitTestStroke = new Stroke(spc2);
                hitTestStroke.DrawingAttributes = stroke.DrawingAttributes;
                //从下标为0的位置开始遍历点迹,直到第一个被擦除的点
                while (true)
                {
                    if (hitTestStroke.StylusPoints.Count > 0)
                    {
                        if (hitTestStroke.StylusPoints.Count > 1)
                        {
                            StylusPoint sp = hitTestStroke.StylusPoints[0];
                            hitTestStroke.StylusPoints.RemoveAt(0);
                            if (!hitTestStroke.HitTest(pointErasePoint, 3))
                            {
                                break;
                            }
                            splitStrokePoints1.Add(sp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }


                // 将原来的stroke删除掉,然后添加两个新的stroke
                if (splitStrokePoints1.Count > 1)
                {
                    Stroke splitStroke1 = new Stroke(splitStrokePoints1);
                    splitStroke1.DrawingAttributes = InkTool.getInstance().DrawingAttributesCopy(stroke.DrawingAttributes);
                    MyStroke         mystroke = new MyStroke(splitStroke1);
                    AddStrokeCommand cmd      = new AddStrokeCommand(_inkCollector, mystroke);
                    _inkCollector.CommandStack.Push(cmd);
                    cmd.execute();
                }


                if (splitStrokePoints2.Count > 1)
                {
                    Stroke splitStroke2 = new Stroke(splitStrokePoints2);
                    splitStroke2.DrawingAttributes = InkTool.getInstance().DrawingAttributesCopy(stroke.DrawingAttributes);
                    MyStroke         mystroke = new MyStroke(splitStroke2);
                    AddStrokeCommand cmd      = new AddStrokeCommand(_inkCollector, mystroke);
                    _inkCollector.CommandStack.Push(cmd);
                    cmd.execute();
                }
            }
            DeleteStrokeCommand dsc = new DeleteStrokeCommand(_inkCollector, stroke);

            _inkCollector.CommandStack.Push(dsc);
            dsc.execute();
        }