如何从WPF控件获取可缩放的图像表示? [英] How to get a scalable image representation from WPF controls?
问题描述
在许多情况下, 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());
在这里,我将一段文字转换成轮廓( 虽然 这就是为什么我要找(或者至少正确的 我不在寻找位图图像 - 我对可缩放表示感兴趣,例如像 我怀疑这可能是可能的,因为我知道打印将任意xaml转换为 / em>图像表示。 有人有什么想法吗? 我想我自己找到了一种方法:WPF允许在XpfDocument中呈现,而不需要将该文档打印或存储在磁盘上。它可以是一个在内存流上初始化的文档。这只是一个重新打开它并解析xaml的问题。 细节上有点棘手,但肯定可能。 I'm trying to "render" text outlines in WPF to from a rich text source. In many cases, the Here, I convert a piece of text to it's outlines ( The That's why I'm looking for a way to "render" arbitrary ui elements (or at least proper I'm not looking for a bitmap image - I'm interested in a scalable representation, for example something like a 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屋! Geometry <
$ b FormattedText
类有一些限制。例如,没有办法从 Typography
类获得 FlowDocument
s或OpenType特性的段落格式。与RichTextBox或任意的ui元素相比,通常对于呈现的内容的控制更为有限。
FlowDocument
s),就像我在代码片段中使用普通文本一样。 b
几何体
实例。
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());
Geometry
) in a specific typeface and size.FormattedText
class has some limitations though. There is no way to get the paragraph formatting of FlowDocument
s 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.FlowDocument
s) into outlines the same way I did with normal text in the snippet.Geometry
instance.