如何使用矩阵转换鼠标坐标?

时间:2013-06-27 09:10:28

标签: c# image-processing matrix

我可以使用此代码获取图像坐标。但我想通过使用Matrix来做同样的事情。

        private int _angle = 90;
        float scaleFactorX = (float)resizeWidth / (float)originalWidth;
        float scaleFactorY = (float)resizeHeight / (float)originalHeight;

        graphics.TranslateTransform((float)(width / 2), (float)(height / 2));
        graphics.ScaleTransform(scaleFactorX, scaleFactorY);
        graphics.RotateTransform(_angle);
        graphics.TranslateTransform(-(float)originalWidth / 2, -(float)originalHeight /2);
        graphics.TransformPoints(System.Drawing.Drawing2D.CoordinateSpace.World, System.Drawing.Drawing2D.CoordinateSpace.Device, point);

提前谢谢大家。

2 个答案:

答案 0 :(得分:1)

如果您传递Graphics.MultiplyTransform类型实例,则可能需要使用Matrix

矩阵类型有一种方法可以转换它:

Matrix mx = new Matrix(); 

Rotate

Scale

Translate

我建议遵循这个顺序而不是先进行平移,因为在这些情况下很容易弄乱旋转中心和旋转轴。

答案 1 :(得分:0)

当您可以学习如何使用矩阵变换坐标时,这是一个非常有用的资源。你需要操作:翻译,旋转 - 它们也很好描述。

http://msdn.microsoft.com/en-us/library/ms536397%28VS.85%29.aspx