[英]CS1503 Cannot convert Matrix to MatrixOrder
I'm quite new to C# programming.我对 C# 编程很陌生。 I would like to run a simple test in MVS for Matrix calculation code as attached.
我想在 MVS 中为所附的矩阵计算代码运行一个简单的测试。
However I obtained the following errors:但是我得到了以下错误:
1) Error CS1503 Argument 2: cannot convert from 'System.Drawing.Drawing2D.Matrix' to 'System.Drawing.Drawing2D.MatrixOrder' 1) 错误 CS1503 参数 2:无法从“System.Drawing.Drawing2D.Matrix”转换为“System.Drawing.Drawing2D.MatrixOrder”
2) Error CS0019 Operator '*' cannot be applied to operands of type 'Matrix' and 'Matrix' 2) 错误 CS0019 运算符“*”不能应用于“矩阵”和“矩阵”类型的操作数
I had tried looking for solutions, but couldn't resolve this errors.我曾尝试寻找解决方案,但无法解决此错误。
Target Framework: .Net Framework 4.7.2 Output Type: Console Application目标框架:.Net Framework 4.7.2 输出类型:控制台应用程序
Please advise.请指教。 Thank You.
谢谢你。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Drawing.Drawing2D;
namespace Project2
{
public class MatrixCalculation
{
static void Main()
{
}
private void MultiplicationExample()
{
Matrix matrix1 = new Matrix(5, 10, 15, 20, 25, 30);
Matrix matrix2 = new Matrix(2, 4, 6, 8, 10, 12);
// matrixResult is equal to (70,100,150,220,240,352)
Matrix matrixResult = Matrix.Multiply(matrix1, matrix2);
// matrixResult2 is also
// equal to (70,100,150,220,240,352)
Matrix matrixResult2 = matrix1 * matrix2;
}
}
}
It is because you are using a System.Drawing.Drawing2D.Matrix
instead of a System.Windows.Media.Matrix
.这是因为您使用的是
System.Drawing.Drawing2D.Matrix
而不是System.Windows.Media.Matrix
。
The System.Drawing.Drawing2D.Matrix.Multiply
method takes one or two parameters. System.Drawing.Drawing2D.Matrix.Multiply
方法采用一两个参数。 The first one being a Matrix
and the optional second one a MatrixOrder
.第一个是
Matrix
,可选的第二个是MatrixOrder
。
Remove this line:删除这一行:
using System.Drawing.Drawing2D;
If the error persists, the you're probably referencing the wrong assembly.如果错误仍然存在,则您可能引用了错误的程序集。
If you're using Visual Studio如果您使用的是 Visual Studio
If you are using the namespace System.Drawing.Drawing2D
, you could do the multiplication like the following:如果您使用命名空间
System.Drawing.Drawing2D
,您可以执行如下乘法:
matrix1.Multiply(matrix2); //matrix1 will have the result.
For reference: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.matrix.multiply?view=netframework-4.8供参考: https : //docs.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.matrix.multiply?view=netframework-4.8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.