Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
InkCanvas demo
#1
Very simplistic sketch app. It can load .isf, save .isf, and clear the canvas.
 
Code:
Copy      Help
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Ink;

var b = new wpfBuilder("Ink Canvas Demo").WinSize(600);

b.R.Add(out InkCanvas canvas0);
canvas0.Background = Brushes.DarkSlateBlue;
canvas0.DefaultDrawingAttributes.Color = Colors.SpringGreen;
canvas0.DefaultDrawingAttributes.Height = 10;
canvas0.DefaultDrawingAttributes.Width = 10;
b.R.StartStack()
    .AddButton("Save", _ => SaveInk()).Width(70)
    .AddButton("Load", _ => LoadInk()).Width(70)
    .AddButton("Clear", _ => ClearInk()).Width(70)
    .AddButton("Exit", 1) //Button closes app and sets ButtonResult
    .End(); //end stack


b.End();

b.ShowDialog();

void SaveInk() {
    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
    saveFileDialog1.Filter = "isf files (*.isf)|*.isf";

    if (saveFileDialog1.ShowDialog() == true)
    {
        FileStream fs = new FileStream(saveFileDialog1.FileName,
                                       FileMode.Create);
        canvas0.Strokes.Save(fs);
        fs.Close();
    }
}

void LoadInk() {
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "isf files (*.isf)|*.isf";

    if (openFileDialog1.ShowDialog() == true)
    {
        FileStream fs = new FileStream(openFileDialog1.FileName,
                                       FileMode.Open);
        canvas0.Strokes = new StrokeCollection(fs);
        fs.Close();
    }
}

void ClearInk() {
            if(canvas0.Strokes.Count != 0)
            {
                while (canvas0.Strokes.Count > 0)
                {
                    canvas0.Strokes.RemoveAt(canvas0.Strokes.Count - 1);
                }
            }
}


Regards,
burque505


Attached Files Image(s)
   


Forum Jump:


Users browsing this thread: 2 Guest(s)