加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何使用Graphics对象在特定角度旋转RectangleF?

发布时间:2020-12-15 21:26:08 所属栏目:百科 来源:网络整理
导读:我试过这个: g.RotateTransform(degrees); 但没有任何反应.我有一个图形对象和一个矩形对象使用此方法绘图: g.FillRectangle(new TextureBrush(Image.FromFile(@"D:LOVELUAPicturesyellowWool.png")),rectangle); 我需要以某种方式旋转矩形并再次绘制它
我试过这个:

g.RotateTransform(degrees);

但没有任何反应.我有一个图形对象和一个矩形对象使用此方法绘图:

g.FillRectangle(new TextureBrush(Image.FromFile(@"D:LOVE&LUAPicturesyellowWool.png")),rectangle);

我需要以某种方式旋转矩形并再次绘制它.

请用代码示例回答并简单解释一下.

编辑:这是我正在使用的实际代码:

public void Draw(Graphics g,PointF location,Color clearColor)
    {
        rectangle.Location = location;
        g.Clear(clearColor);
        g.RotateTransform(10);
        //g.FillRectangle(new SolidBrush(Color),rectangle);
        g.FillRectangle(new TextureBrush(Image.FromFile(@"D:LOVE&LUAPicturesyellowWool.png")),rectangle);
    }

每个框架我调用这个函数,我正在使用窗体的Paint事件的e.Graphics对象的图形,我有一个计时器只会调用this.Refresh();

编辑2:
好的我已经玩了一些转换和g.RotateTransform旋转graphycs对象的整个坐标系统我需要只旋转矩形而不改变坐标系统

解决方法

您可以尝试使用带有RotateAt方法的矩阵来围绕矩形居中旋转:

using (Matrix m = new Matrix()) {
  m.RotateAt(10,new PointF(rectangle.Left + (rectangle.Width / 2),rectangle.Top + (rectangle.Height / 2)));
  g.Transform = m;
  using (TextureBrush tb = new TextureBrush(Image.FromFile(@"D:LOVE&LUAPicturesyellowWool.png"))
    g.FillRectangle(tb,rectangle);
  g.ResetTransform();
}

之后,ResetTransform()会将图形恢复为正常处理.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读