使用:Matrix myMatrix = new Matrix(1, 0, 0, -1, 0, 0);
PictureBox.CreateGraphics().Transform = myMatrix;可以把该PictureBox的坐标系变为:中心在原点,X正向右,Y正向上。但是,当我在它上面使用DrawString时,字所在的位置正确,但是字却是翻转过的。请问,怎么才能让字是正的,无翻转。
PictureBox.CreateGraphics().Transform = myMatrix;可以把该PictureBox的坐标系变为:中心在原点,X正向右,Y正向上。但是,当我在它上面使用DrawString时,字所在的位置正确,但是字却是翻转过的。请问,怎么才能让字是正的,无翻转。
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);
这个坐标系没变,还在左上角。不信你输出两个,一个“AA”(40,40),一个“CC”(50,50),你看看它们的位置就知道了。
你问题在PictureBox.CreateGraphics()上
以上是效果下面是代码:
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);
y1 = height - y;如果非得进行翻转,那么在你绘制文字之前,再次对坐标系进行旋转就行。GraphicsContainer c = e.Graphics.BeginContainer();
Graphics.Transform.RotateAt(180,x,y);
Graphics.DrawString(.....
//恢复Rotate之前的坐标系
e.Graphics.EndContainer(c);
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_fxmclignrl/html/b601d66d-d572-4f11-9d2e-92f0dc8893f3.htm