绘制旋转文字到图像在C#

编程入门 行业动态 更新时间:2024-10-22 18:48:10
本文介绍了绘制旋转文字到图像在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是图形类的束带方法绘制的图像的字符串。

I'm using the the drawstring method of Graphics class to draw a String on Image.

g.DrawString(mytext, font, brush, 0, 0);

我试图用旋转的旋转变换图形对象的功能,使文本可以在任何angle.How我能做到这一点使用旋转变换绘制由角文本。 该旋转变换code我用的是

I'm trying to rotate the text by angle using the Rotate Transform Function of the graphic object so that the text can be drawn at any angle.How can i do it using Rotate Transform. The rotate Transform Code i used is

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;

文字是画在一个旋转的角度,但它不是画在中间,我want.Plz帮助我。

The Text is Drawn at a rotated angle but it is not drawn at the centre as i want.Plz help me out.

推荐答案

这是不够的,只是 RotateTransform 或 TranslateTranform 如果要居中的文本。您需要抵消文本的起点,也通过测量:

It's not enough to just RotateTransform or TranslateTranform if you want to center the text. You need to offset the starting point of the text, too, by measuring it:

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旋转文本+?

更多推荐

绘制旋转文字到图像在C#

本文发布于:2023-11-13 01:52:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   文字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!