【问题标题】:Using Win2D is it possible to get text size without a drawingSession?使用 Win2D 是否可以在没有绘图会话的情况下获得文本大小?
【发布时间】:2020-10-05 00:20:24
【问题描述】:

这个问题与这个问题不同 - How to calculate the size of a piece of text in Win2D - 因为该方法将结果附加到 Win2D CanvasControl 的绘制事件。具体来说,它需要参数的 DrawingSession。

我想知道是否可以在不调用绘图函数的情况下知道文本的大小。这是理想的,因为我需要使用宽度或高度的各种 CanvasControls 才能通过文本大小进行设置。

【问题讨论】:

    标签: win2d


    【解决方案1】:

    使用文本和格式创建CanvasTextLayout 类的实例并获取它的DrawBounds 属性。

    using (var layout = new CanvasTextLayout(creator, "Hello world", format, 200, 100))
    {
       var bounds = layout.DrawBounds;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-31
      • 1970-01-01
      相关资源
      最近更新 更多