关于坐标的变换问题后,字也翻转的问题

白羊佐 2010-09-14 04:55:38
使用:

Matrix myMatrix = new Matrix(1, 0, 0, -1, 0, 0);
PictureBox.CreateGraphics().Transform = myMatrix;

可以把该PictureBox的坐标系变为:中心在原点,X正向右,Y正向上。

但是,当我在它上面使用DrawString时,字所在的位置正确,但是字却是翻转过的。

请问,怎么才能让字是正的,无翻转。
...全文
179 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
白羊佐 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 kingweaver1 的回复:]
坐标系的变换会完全作用在绘制的图元上的,你整个坐标系发转,绘制的任何东西也都是反过来的。

如果仅仅是你说的效果,自己维护一个视图坐标系对坐标系进行平移就行了,不要进行发转.

x1 = x;
y1 = height - y;

如果非得进行翻转,那么在你绘制文字之前,再次对坐标系进行旋转就行。

GraphicsContainer c = e.Graphics.BeginCon……
[/Quote]
这我也考虑过,但TNND,MSDN帮助里的例子却画出来了,不知道中间咋搞的
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_fxmclignrl/html/b601d66d-d572-4f11-9d2e-92f0dc8893f3.htm
kingweaver1 2010-10-14
  • 打赏
  • 举报
回复
坐标系的变换会完全作用在绘制的图元上的,你整个坐标系发转,绘制的任何东西也都是反过来的。

如果仅仅是你说的效果,自己维护一个视图坐标系对坐标系进行平移就行了,不要进行发转.

x1 = x;
y1 = height - y;

如果非得进行翻转,那么在你绘制文字之前,再次对坐标系进行旋转就行。

GraphicsContainer c = e.Graphics.BeginContainer();
Graphics.Transform.RotateAt(180,x,y);
Graphics.DrawString(.....
//恢复Rotate之前的坐标系
e.Graphics.EndContainer(c);
白羊佐 2010-10-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 chuxue1342 的回复:]
多贴点代码~~~没搞清楚你要什么效果呢~
[/Quote]

以上是效果

下面是代码:
            Graphics gs = picBDot.CreateGraphics();

Matrix myMatrix = new Matrix(1, 0, 0, -1, 0, 0);

gs.Transform = myMatrix;

gs.TranslateTransform((float)picBDot.Width / 2, (float)picBDot.Height / 2, MatrixOrder.Append);

gs.DrawString("你好!", new Font("黑体", 20f), new SolidBrush(Color.Black), new PointF(10, 10));

gs.DrawString("他也好!", new Font("黑体", 20f), new SolidBrush(Color.Black), new PointF(50, 50));

gs.DrawLine(new Pen(Color.Black), -picBDot.Width / 2, 0, picBDot.Width / 2, 0);

gs.DrawLine(new Pen(Color.Black), 0, -picBDot.Height / 2, 0, picBDot.Height / 2);
chuxue1342 2010-10-14
  • 打赏
  • 举报
回复
多贴点代码~~~没搞清楚你要什么效果呢~
白羊佐 2010-10-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xshf12345 的回复:]
我试了下,没出现你说的那种情况

C# code
pictureBox1.ImageLocation = @"c:\22234014I7.jpg";
Matrix myMatrix = new Matrix(1, 0, 0, -1, 0, 0);
//PictureBox.CreateGraphics().Transform = myMat……
[/Quote]

这个坐标系没变,还在左上角。不信你输出两个,一个“AA”(40,40),一个“CC”(50,50),你看看它们的位置就知道了。
你问题在PictureBox.CreateGraphics()上
xshf12345 2010-09-21
  • 打赏
  • 举报
回复
我试了下,没出现你说的那种情况
pictureBox1.ImageLocation = @"c:\22234014I7.jpg";
Matrix myMatrix = new Matrix(1, 0, 0, -1, 0, 0);
//PictureBox.CreateGraphics().Transform = myMatrix;
Label l = new Label();
l.Text = "ss";

pictureBox1.CreateGraphics().Transform = myMatrix;
pictureBox1.CreateGraphics().DrawString("你好,C#!",new Font("Verdana",20), new SolidBrush(Color.Tomato),40,40);
HaveOneDream 2010-09-21
  • 打赏
  • 举报
回复
设置字的坐标与原来的相反,反反得正啊
白羊佐 2010-09-15
  • 打赏
  • 举报
回复
不行,画完的字符还在原地方,若再画的话,就使用新的坐标系
libolei 2010-09-14
  • 打赏
  • 举报
回复
能不能画完字符串了 再重新设置坐标系啊?

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧