InkCanvas加载/保存操作 [英] InkCanvas Load/Save operations

查看:662
本文介绍了InkCanvas加载/保存操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从未使用过InkCanvas控件.我需要的是将文件加载到InkCanvas中,进行一些涂抹,然后获得最终的图像.我想对获得的图像进行一些其他操作.

I've never used InkCanvas control before. What I need is to load up a file into InkCanvas, draw some scribbles and get ther resulting image. And I want to make some additional operations with gotten image.

如果我错了,请纠正我.我找到了一个链接: http://www.centrolutions.com/Blog/post/2008/12/09/Convert-WPF-InkCanvas-to-Bitmap.aspx 根据帖子将加载除用户涂鸦之外的图像.还是只将涂鸦转换为位图?

Correct me if I'm wrong. I've found a link: http://www.centrolutions.com/Blog/post/2008/12/09/Convert-WPF-InkCanvas-to-Bitmap.aspx According to the post will be loaded image considered in addition to user scribbles. Or it only converts scribbles to bitmap?

如何使用OpenFileDialog加载图像?我不想使用ISF.

How do I load image using OpenFileDialog? I don't want to use ISF.

谢谢!

推荐答案

保存:

如果要在保存后能够操作笔划,则需要保存笔划.您可以使用 StrokeCollection.Save 方法.

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.

正在加载

将位图加载到Image控件很简单,因为OpenFileDialog会返回图像路径.

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.

我认为您不能直接将位图加载到InkCanvas.但是,您可以改为加载笔划.

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

要再次加载笔划,可以使用 StrokeCollection(Stream)

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;

有关更多功能,您可以阅读 CodeProject文章.

For more functions, you can read this CodeProject article.

这篇关于InkCanvas加载/保存操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆