Exemple #1
0
        public string GetJSON()
        {
            SegmentSerializable segmSer = new SegmentSerializable();

            segmSer.image         = ImageToString(image);
            segmSer.point         = position;
            segmSer.selectionType = selectionStrategy.GetType().Name;

            switch (selectionStrategy.GetType().Name)
            {
            case "RectangleSelection":
            {
                segmSer.rect = ((RectangleSelection)selectionStrategy).selectionRectangle;
                break;
            }

            case "EllipseSelection":
            {
                segmSer.rect = ((EllipseSelection)selectionStrategy).selectionRectangle;
                break;
            }

            case "PolygonSelection":
            {
                segmSer.newPoints = ((PolygonSelection)selectionStrategy).newPoints;
                break;
            }
            }
            string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(segmSer);

            return(jsonString);
        }
Exemple #2
0
        public Segment(string json)
        {
            SegmentSerializable segmSer = Newtonsoft.Json.JsonConvert.DeserializeObject <SegmentSerializable>(json);

            image    = StringToImage(segmSer.image);
            position = segmSer.point;
            switch (segmSer.selectionType)
            {
            case "RectangleSelection":
            {
                selectionStrategy = new RectangleSelection(Scene.instance);
                ((RectangleSelection)selectionStrategy).selectionRectangle = segmSer.rect;
                break;
            }

            case "EllipseSelection":
            {
                selectionStrategy = new EllipseSelection(Scene.instance);
                ((EllipseSelection)selectionStrategy).selectionRectangle = segmSer.rect;
                break;
            }

            case "PolygonSelection":
            {
                selectionStrategy = new PolygonSelection(Scene.instance);
                ((PolygonSelection)selectionStrategy).newPoints = segmSer.newPoints;
                break;
            }
            }
        }