如何将比例转换应用于DrawingContext? [英] How do you apply a Scale Translation to a DrawingContext?

查看:118
本文介绍了如何将比例转换应用于DrawingContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Canvas,在XAML中应用了比例转换.使用DrawingContext我在Canvas上画线.我现在需要在屏幕上添加文本.我以为格式化文本可以应用翻译,但是格式化文本或DrawingContext都不接受RenderTransform.如何对文本应用比例尺转换,以便抵消画布的比例尺转换?

I have a Canvas with a scale translation applied in XAML. Using DrawingContext I draw lines on the Canvas. I now need to add text to the screen. I thought with formatted text I could apply a translation, but neither Formatted Text or DrawingContext accepts RenderTransform. How do I apply a scale translation to the text so it will counter the scale translation of the canvas?

 ftext = New FormattedText("N", CultureInfo.GetCultureInfo("en-us"), Windows.FlowDirection.LeftToRight, face, Me.DBFontSize, FalconDataBlock.Foreground)
 context.DrawText(ftext, .TargetLineInfo.EndAsWinPoint)

推荐答案

在大多数UI应用程序中,正确的做法可能是将子TextBlock添加到Canvas,然后更改TextBlock的RenderTransform,而不是使用DrawingContext.

In most UI apps, instead of using a DrawingContext, the right thing to do might be to add a child TextBlock to the Canvas, and change the TextBlock's RenderTransform.

但是,假设您有充分的理由使用DrawingContext,则可以使用 DrawingContext.Pop 恢复使用DrawText完成操作后的先前状态.

However, assuming you have a good reason for using a DrawingContext, you could use DrawingContext.PushTransform to push the transform you need (scale, translation, etc.), just before you invoke DrawText. Use DrawingContext.Pop to restore the prior state after you're done with DrawText.

这篇关于如何将比例转换应用于DrawingContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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