如何从WPF控件获取可缩放的图像表示? [英] How to get a scalable image representation from WPF controls?

查看:199
本文介绍了如何从WPF控件获取可缩放的图像表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在许多情况下, TextFormatter class做了我想要的,就像这段代码所示:

  var tf = new Typeface(
新的System.Windows.Media.FontFamily(Pericles),
FontStyles.Normal,
FontWeights.Normal,
FontStretch()
);

var brush = new SolidColorBrush(Colors.Black);

var ftext = new FormattedText(
text,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
tf,
72,

);

var geometry = ftext.BuildGeometry(new Point());

在这里,我将一段文字转换成轮廓( Geometry <
$ b

虽然 FormattedText 类有一些限制。例如,没有办法从 Typography 类获得 FlowDocument s或OpenType特性的段落格式。与RichTextBox或任意的ui元素相比,通常对于呈现的内容的控制更为有限。



这就是为什么我要找(或者至少正确的 FlowDocument s),就像我在代码片段中使用普通文本一样。 b

我不在寻找位图图像 - 我对可缩放表示感兴趣,例如像几何体实例。



我怀疑这可能是可能的,因为我知道打印将任意xaml转换为 / em>图像表示。

有人有什么想法吗?

解决方案

我想我自己找到了一种方法:WPF允许在XpfDocument中呈现,而不需要将该文档打印或存储在磁盘上。它可以是一个在内存流上初始化的文档。这只是一个重新打开它并解析xaml的问题。



细节上有点棘手,但肯定可能。


I'm trying to "render" text outlines in WPF to from a rich text source.

In many cases, the TextFormatter class does what I want, as in this snippet:

var tf = new Typeface(
  new System.Windows.Media.FontFamily("Pericles"),
  FontStyles.Normal,
  FontWeights.Normal,
  new FontStretch()
);

var brush = new SolidColorBrush(Colors.Black);

var ftext = new FormattedText(
  text,
  CultureInfo.CurrentCulture,
  FlowDirection.LeftToRight,
  tf,
  72,
  brush
);

var geometry = ftext.BuildGeometry(new Point());

Here, I convert a piece of text to it's outlines (Geometry) in a specific typeface and size.

The FormattedText class has some limitations though. There is no way to get the paragraph formatting of FlowDocuments or OpenType features available from the Typography class, for example. There is generally a much more limited control over what it renders when compared to what I could do with a RichTextBox or arbitrary ui elements.

That's why I'm looking for a way to "render" arbitrary ui elements (or at least proper FlowDocuments) into outlines the same way I did with normal text in the snippet.

I'm not looking for a bitmap image - I'm interested in a scalable representation, for example something like a Geometry instance.

I suspect it might be possible because I know printing does a conversion of arbitrary xaml to a scalable image representation. I just don't want it actually printed.

Does anybody have any ideas?

解决方案

I think I found a way myself:

WPF allows to render in an XpfDocument without needing that document to be printed or stored on disk. It can be a document initialized on a memory stream. It is then "only" a matter of re-opening it and parse the xaml inside.

A bit tricky in the details perhaps, but certainly possible.

这篇关于如何从WPF控件获取可缩放的图像表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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