在C#中将旋转的文本绘制到图像
我正在使用Graphics类的drawtring方法在Image上绘制一个String。
g.DrawString(mytext, font, brush, 0, 0);
我正在尝试使用图形对象的旋转变换function按角度旋转文本,以便可以以任何角度绘制文本。如何使用旋转变换来执行此操作。 我使用的旋转变换代码是
Bitmap m = new Bitmap(pictureBox1.Image); Graphics x=Graphics.FromImage(m); x.RotateTransform(30); SolidBrush brush = new SolidBrush(Color.Red); x.DrawString("hi", font,brush,image.Width/2,image.Height/2); //image=picturebox1.image pictureBox1.Image = m;
文本是以旋转的角度绘制的,但它不是在我想要的中心绘制.Plz帮助我。
如果要将文本居中,仅仅使用RotateTransform
或TranslateTranform
是不够的。 您还需要通过测量来偏移文本的起始点:
Bitmap bmp = new Bitmap(pictureBox1.Image); using (Graphics g = Graphics.FromImage(bmp)) { g.TranslateTransform(bmp.Width / 2, bmp.Height / 2); g.RotateTransform(30); SizeF textSize = g.MeasureString("hi", font); g.DrawString("hi", font, Brushes.Red, -(textSize.Width / 2), -(textSize.Height / 2)); }
从如何在GDI +中旋转文本?
在g.DrawString(mytext, font, brush, 0, 0);
之前g.DrawString(mytext, font, brush, 0, 0);
使用g.RotateTransform(45);
上述就是C#学习教程:在C#中将旋转的文本绘制到图像分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1044056.html