【问题标题】:What is the best way to convert between a Media.Matrix to a Drawing2D.Matrix在 Media.Matrix 到 Drawing2D.Matrix 之间转换的最佳方法是什么
【发布时间】:2009-04-15 21:04:54
【问题描述】:

我需要从 WPF Media.Matrix 转换为 Windows 窗体 Drawing2D.Matrix,所以我做了以下操作:

  public static System.Drawing.Drawing2D.Matrix ConvertToDrawing2DMatrix( Matrix matrix)
  {
     return new System.Drawing.Drawing2D.Matrix((float)matrix.M11, 
                                                (float)matrix.M12, 
                                                (float)matrix.M21, 
                                                (float)matrix.M22,
                                                (float)matrix.OffsetX, 
                                                (float)matrix.OffsetY);
  }

并且想知道这是否是最好的方法。

【问题讨论】:

    标签: c# .net wpf winforms geometry


    【解决方案1】:

    如果您的代码工作正常,那么我会说这可能是您情况下的最佳方法。 我查看了整个谷歌,试图找到一种方法来做到这一点,而不是我的第 3 方库似乎找不到办法。

    【讨论】:

      【解决方案2】:

      正如其他人所说,这可能是最好的方法。我只是想根据 .NET 版本和您的编码策略添加它,您可以考虑将“this”添加到方法签名中,并使其成为更易于访问的扩展方法,如下所示:

      using Drawing2DMatrix = System.Drawing.Drawing2D.Matrix;
      public static Drawing2DMatrix ConvertToDrawing2DMatrix(this Matrix matrix) {...}
      

      那么你可以这样称呼它:

      Drawing2DMatrix newMatrix = myMediaMatrixInstance.ConvertToDrawing2DMatrix();
      

      只是一个建议。

      【讨论】:

        【解决方案3】:

        我会说这是最好的方法。 System.Drawing 矩阵存储在非托管内存中,而 WPF 矩阵是托管堆栈上的一个结构,因此在进行块复制时的任何技巧都需要一些不安全的代码来实现非常小的性能改进(如果有的话)。

        【讨论】:

          猜你喜欢
          • 2021-09-29
          • 1970-01-01
          • 1970-01-01
          • 2011-08-16
          • 2011-03-20
          • 1970-01-01
          • 2010-09-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多