private static string StrokeToString(StrokeCollection sc) { StrokeCollectionConverter converter = new StrokeCollectionConverter(); string stringStroke = (string)converter.ConvertToString(sc); return(stringStroke); }
private void SetupSlika(string path) { //Struktura struktura = new Struktura(); //XmlSerializer serializer = new XmlSerializer(typeof(Struktura)); //try //{ // using (FileStream fileStream = new FileStream(path, FileMode.Open)) // { // struktura = (Struktura)serializer.Deserialize(fileStream); // } // Struktura = struktura; // if (Struktura.Slika == null) // { // struktura.Slika = new Point[0][]; // } // for (int i = 0; i < Struktura.Slika.Length; i++) // { // if (struktura.Slika[i] != null) // { // StylusPointCollection stylusCollection = new // StylusPointCollection(struktura.Slika[i]); // Stroke stroke = new Stroke(stylusCollection); // StrokeCollection strokes = new StrokeCollection(); // strokes.Add(stroke); // PaintCanvas.Strokes.Add(strokes); // } // } //} //catch (Exception) //{ //} Struktura struktura = new Struktura(); XmlSerializer serializer = new XmlSerializer(typeof(Struktura)); try { using (FileStream fileStream = new FileStream(path, FileMode.Open)) { struktura = (Struktura)serializer.Deserialize(fileStream); } Struktura = struktura; StrokeCollectionConverter strokeCollectionConverter = new StrokeCollectionConverter(); PaintCanvas.Strokes = (StrokeCollection)strokeCollectionConverter.ConvertFromString(Struktura.Strokes); } catch (Exception) { } }
private void SaveSlika() { //var strokes = PaintCanvas.Strokes; //if (strokes.Count > 0) //{ // Struktura.Slika = new Point[strokes.Count][]; // for (int i = 0; i < Struktura.Slika.Length; i++) // { // Struktura.Slika[i] = // new Point[this.PaintCanvas.Strokes[i].StylusPoints.Count]; // for (int j = 0; j < strokes[i].StylusPoints.Count; j++) // { // Struktura.Slika[i][j] = new Point(); // Struktura.Slika[i][j].X = // strokes[i].StylusPoints[j].X; // Struktura.Slika[i][j].Y = // strokes[i].StylusPoints[j].Y; // } // } // XmlSerializer serializer = new XmlSerializer(typeof(Struktura)); // //Struktura.Slika = new Point[PaintCanvas.Strokes.Count][]; // using (FileStream fileStream = new FileStream(Struktura.FileName, FileMode.Create)) // { // serializer.Serialize(fileStream, Struktura); // } //} //JeShranjen = true; var strokes = PaintCanvas.Strokes; StrokeCollectionConverter strokeCollectionConverter = new StrokeCollectionConverter(); string str = strokeCollectionConverter.ConvertToString(strokes); if (strokes.Count > 0) { Struktura.Strokes = str; XmlSerializer serializer = new XmlSerializer(typeof(Struktura)); //Struktura.Slika = new Point[PaintCanvas.Strokes.Count][]; using (FileStream fileStream = new FileStream(Struktura.FileName, FileMode.Create)) { serializer.Serialize(fileStream, Struktura); } } JeShranjen = true; }
//<Snippet3> // Accepts a string that contains ink data in ink // serialized format (ISF) and converts it into a StrokeCollection. public void LoadStrokes() { StrokeCollectionConverter converter = new StrokeCollectionConverter(); if (converter.CanConvertFrom(typeof(string))) { StrokeCollection newStrokes = (StrokeCollection)converter.ConvertFrom(null, null, strokesString); presenter.Strokes.Clear(); presenter.Strokes.Add(newStrokes); } }
public InkEraser() { presenter = new InkPresenter(); this.Content = presenter; // Create a StrokeCollection the string and add it to StrokeCollectionConverter converter = new StrokeCollectionConverter(); if (converter.CanConvertFrom(typeof(string))) { StrokeCollection newStrokes = converter.ConvertFrom(strokesString) as StrokeCollection; presenter.Strokes.Clear(); presenter.Strokes.Add(newStrokes); } }
private static StrokeCollection StringToStroke(string stroke) { StrokeCollectionConverter converter = new StrokeCollectionConverter(); return((StrokeCollection)converter.ConvertFromString(stroke)); }