在新对象上实现矩阵变换
我需要能够将我自己的对象之一与 .Net 中的一些 GraphicsPath 对象一起转换。我需要在 GraphicsPath 对象上执行的任何缩放、平移、旋转操作也发生在我自己的对象上。
例如,这是一些缩放代码:
using (Matrix ScaleTransform = new Matrix(1, 0, 0, 1, 0, 0)) // scale matrix
{
ScaleTransform.Scale(ScaleX, ScaleY);
moPath.Transform(ScaleTransform);
moBoundingBox.Transform(ScaleTransform);
MyObject.Transform(ScaleTranform);
}
//In "MyObject":
public void Transform(Matrix m)
{
//How is this implemented? Is there a built-in .Net method?
}
问题是: 在 MyObject 中实现“Transform”方法的最佳方法是什么?我做了很多搜索,但找不到任何关于最佳方法的参考资料。
谢谢!
I need to be able to transform one of my own objects along with some GraphicsPath objects in .Net. I need any scaling, translation, rotation operations that are performed on the GraphicsPath objects to also occur on my own object.
For example, here is some scaling code:
using (Matrix ScaleTransform = new Matrix(1, 0, 0, 1, 0, 0)) // scale matrix
{
ScaleTransform.Scale(ScaleX, ScaleY);
moPath.Transform(ScaleTransform);
moBoundingBox.Transform(ScaleTransform);
MyObject.Transform(ScaleTranform);
}
//In "MyObject":
public void Transform(Matrix m)
{
//How is this implemented? Is there a built-in .Net method?
}
The question is:
What is the best way to implement the "Transform" method in MyObject. I did quite a bit of searching, but couldn't find any references for the best way to do this.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自己实现转换并不是很难,请看一下:
http://en.wikipedia.org/wiki /Transformation_matrix
那么你的对象是位图还是其他东西?那么这可能是某种方式:
http://en.csharp-online。 net/GDIplus_Graphics_Transformation%E2%80%94Image_Transformation
或者,您可以保留对象并将转换推送到堆栈,并在您需要时使用它。将其制作成图形。
嘿 - 看起来 Matrix 类可以为您做很多事情:
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx
例如
Implementing the transform yourself is not very hard, take a look at:
http://en.wikipedia.org/wiki/Transformation_matrix
So is your object a bitmap or something? Then this might be some of the way:
http://en.csharp-online.net/GDIplus_Graphics_Transformation%E2%80%94Image_Transformation
Or you could leave your object and push the transformation to a stack and use it when you make it into graphics.
Hey - it looks like the Matrix class can do a lot for you:
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx
For example