0

在我的应用程序中,用户可以创建多个对象(所谓的绘图),每个对象都有一个 SurfaceInkCanvas,与 SDKSamples(由 MS Surface SP1 SDK 提供)中的 Photopad(Photo Paint 应用程序)非常相似。考虑到可能创建了数十甚至数百个,保存inkCanvas(绘图对象)内容的最佳方法是什么。

经过一番研究,弹出了一个选项:将其转换为图像、jpg 或 png,但这种方法似乎不是可扩展的 IMO。

是否可以将点存储在数据库中(最好是 sqlite)?

目标是能够在加载时恢复绘图(inkCanvas 的内容)以进行进一步编辑。

4

2 回答 2

2

Saving to an image isn't really viable for what it sounds like you want to do because restoring vector lines from a bitmap is much harder and potentially lossy than the vector to bitmap conversion, in addition to not being very efficient from a data density perspective.

You could write some code to save and restore the collection of lines that's stored in the Strokes property. This would allow you to reduce the size of your data down to a minimum and easily store in a database. Each Stroke has some data about what the line looks like and a set of points that make up the line. It's fairly simple to extract and restore that data to another InkCanvas when reloading.

You might also be able to use XamlWriter/XamlReader to just serialize the entire InkCanvas to xml but you would need to be able to put the new deserialized instance into your UI and make sure there aren't any naming or resource complications in your XAML that tend to cause errors with this method.

于 2010-07-13T19:56:01.080 回答
2

微软已经有一种用于保存笔画的格式,即 ISF——代表将笔画集合保存在 .isf 文件中的 Ink Serialized 格式。

但是,在示例中,每个图形都保存在一个单独的(但很小的).isf 文件中,可以轻松加载该文件以进行进一步编辑甚至将其转换(导出)为位图。

因此,一个好的方法是将每个绘图保存在文件中(尽管这比简单地将其存储在 sqlite db 中更昂贵,时间方面)并将每个绘图的路径与数据库中的 id 一起保存以识别每个会话。从可扩展性的角度进一步优化此方法有什么建议吗?

于 2010-07-14T10:00:52.970 回答