InkCanvas load / save operations

I have never used a control before InkCanvas. I need to upload a file to InkCanvas, draw some scribbles and get the resulting image. And I want to do some additional operations with the resulting image.

Regarding conservation

Correct me if I am wrong. I found the link: http://www.centrolutions.com/Blog/post/2008/12/09/Convert-WPF-InkCanvas-to-Bitmap.aspx According to the message, the image will be downloaded, which is considered in addition to the custom scribbles. Or does it only convert the scribbles to a bitmap?

Regarding the download

How to upload image using OpenFileDialog? I do not want to use ISF.

Thank!

+3
source share
1 answer

Preservation:

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

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

Then you can download it again and access individual strokes. However, as soon as you render it (for example, in a bitmap image), this displayed file can only be loaded as a bitmap image, 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 that you posted.

Loading

Loading a bitmap into an Image control is easy as it OpenFileDialogwill return the path to the image.

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

.

: , InkCanvas. .

, StrokeCollection (Stream)

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

CodeProject.

+5

All Articles