【问题标题】:How to transform path instead of transforming Canvas in Skiasharp?如何在 Skiasharp 中转换路径而不是转换 Canvas?
【发布时间】:2021-11-13 17:03:21
【问题描述】:

在 Skiasharp 中,我有一个变换矩阵,我将其应用于画布以移动路径并跟随鼠标的位移。目前,我根据鼠标坐标计算了一个 transformMatrix,并且一切正常:

    canvas.Save();                  // Save the actuel transform matrix
    SKMatrix ZoomMatrix = canvas.TotalMatrix.PostConcat(transformMatrix);
    canvas.SetMatrix(ZoomMatrix);   // Apply the matrix for actual Transform
    canvas.DrawPath(Path, paint);
    canvas.Restore();               // And restore the initial transform matrix

但实际上我需要转换路径本身而不是“移动”画布。如果我使用:

    Path.Transform(transformMatrix);
    canvas.DrawPath(Path, paint);

路径与移动画布时不在同一位置 ?!?计算正确的变换矩阵以应用于路径以获得相同结果的任何想法?

只是为了确定(我不知道提及它是否重要),但画布的矩阵不再是单位矩阵。当然在测试期间它不会改变!

【问题讨论】:

    标签: canvas skiasharp skia


    【解决方案1】:

    好吧,我的方法完全错了......!

    当路径移动时,不是对画布应用矩阵变换(这是移动或重新缩放画布本身时的正确方法),在这种情况下,解决方案是直接变换路径本身:

        SelectedPath.Transform(SKMatrix.CreateTranslation(dx, dy));
    

    就是这么简单……

    【讨论】:

      猜你喜欢
      • 2019-08-26
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 2018-06-24
      • 2018-12-04
      • 1970-01-01
      相关资源
      最近更新 更多