I'm quite new to C# programming. I would like to run a simple test in MVS for Matrix calculation code as attached.
However I obtained the following errors:
1) Error CS1503 Argument 2: cannot convert from 'System.Drawing.Drawing2D.Matrix' to 'System.Drawing.Drawing2D.MatrixOrder'
2) Error CS0019 Operator '*' cannot be applied to operands of type 'Matrix' and 'Matrix'
I had tried looking for solutions, but couldn't resolve this errors.
Target Framework: .Net Framework 4.7.2 Output Type: Console Application
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
.
The System.Drawing.Drawing2D.Matrix.Multiply
method takes one or two parameters. The first one being a Matrix
and the optional second one a 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
If you are using the namespace System.Drawing.Drawing2D
, you could do the multiplication like the following:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.