InkCanvas Load/Save operations

六月ゝ 毕业季﹏ 提交于 2019-12-04 14:57:19

Saving:

If you want to be able to manipulate strokes after saving, then you need to save the strokes. You can do this by using the StrokeCollection.Save method.

var fs = new FileStream(inkFileName, FileMode.Create);
inkCanvas1.Strokes.Save(fs);

You can then load this again and have the individual strokes accessible. However, once you render it out (e.g. to a bitmap) then that rendered file can only be loaded as a Bitmap and not individual strokes. (Of course, you can do both and save the strokes as a separate file). To save as a bitmap, you can use the code in the link you posted to.

Loading

Loading a bitmap to an Image control is straightforward since the OpenFileDialog will return the image path.

if (myOpenFileDialog.ShowDialog() == DialogResult.OK)
{
    myImageControl.Source = new BitmapImage(new Uri(myOpenFileDialog.FileName, UriKind.Absolute));
}

That will load the image and display it in an image control on your form.

Edit: I don't think you can load a bitmap straight to an InkCanvas. However, you can load the strokes instead.

To load the strokes again, you can use StrokeCollection(Stream)

var fs = new FileStream(inkFileName,
                FileMode.Open, FileAccess.Read);
StrokeCollection strokes = new StrokeCollection(fs);
inkCanvas1.Strokes = strokes;

For more functions, you can read this CodeProject article.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!