0

我在 Windows 窗体应用程序的图形上下文中绘制了许多图形对象。与渲染路径的 ui 元素有一些交互,允许用户平移、缩放和设置缩放点的原点。我的问题是,是否可以在图形对象上设置一系列变换操作,如下所示?

[1] 应用平移变换(将路径移动到缩放变换的原点) [2] 应用缩放变换 [3] 应用平移变换(将路径移回正确的位置)

似乎我只能订购单个变换操作类型(平移、缩放等),因此两个平移变换不会应用于正确的点(缩放操作的任一侧)。有没有办法做到这一点?或者,是否可以为比例变换设置原点?

我确实弄乱了嵌套的图形容器,但它们似乎没有帮助。

谢谢,

最大限度

4

2 回答 2

2

替代文字 http://lh6.ggpht.com/_1TPOP7DzY1E/S02rsQo3HgI/AAAAAAAAC60/l0rayOPKuoo/s800/Capture5.png

代码:

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    Bitmap bmp = new Bitmap(300, 300);
    Graphics g = Graphics.FromImage(bmp);
    System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();

    g.DrawString("this is a string", SystemFonts.DefaultFont,
        Brushes.Black, new Point(50, 50));

    matrix.Rotate(30); // or use RotateAt(...) specifying your rotation point
    g.Transform = matrix;
    g.DrawString("this is a 30 rotated string", SystemFonts.DefaultFont, 
        Brushes.Black, new Point(50, 50));

    matrix.Reset();
    matrix.Translate(50, 50);
    g.Transform = matrix;
    g.DrawString("this is a 50; 50 translated string", SystemFonts.DefaultFont, 
        Brushes.Black, new Point(50, 50));
    pictureBox1.Image = bmp;
}

您可以使用 Matrix 来转换 GraphicPath 或 Graphics 对象。

于 2010-01-13T11:17:51.913 回答
1

是的。你可以。使用矩阵对象。

http://en.csharp-online.net/GDIplus_Graphics_Transformation%E2%80%94Matrix_Class_and_Transformation

于 2010-01-13T11:10:16.453 回答