Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 添加到图像的文本在边缘处截断_C#_Image_Text - Fatal编程技术网

C# 添加到图像的文本在边缘处截断

C# 添加到图像的文本在边缘处截断,c#,image,text,C#,Image,Text,我试图在图像上添加文本,如果文本很短,效果会很好。但是,如果我添加更长的文本,它将在边缘处被截断 如果课文太长,我需要换一行 以下是我目前掌握的代码: Graphics graphicImage = Graphics.FromImage(bitMapImage); //Smooth graphics is nice. graphicImage.SmoothingMode = SmoothingMode.AntiAlias; Font font = new Font("Tahoma", 6);

我试图在图像上添加文本,如果文本很短,效果会很好。但是,如果我添加更长的文本,它将在边缘处被截断

如果课文太长,我需要换一行

以下是我目前掌握的代码:

Graphics graphicImage = Graphics.FromImage(bitMapImage);

//Smooth graphics is nice.
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
Font font = new Font("Tahoma", 6);
int x_axis = 50;
int y_axis = 120;
int distance = 50;
graphicImage.DrawString("This is a very long text and this long text might come to a new line below", font, Brushes.Yellow, new PointF(x_axis, y_axis + distance * 2));

String tempFile = folder + "output.jpeg";
bitMapImage.Save(tempFile, ImageFormat.Jpeg);
这是它创造的图像


如何使文本换行?

在矩形中绘制文本,它将换行:

string text1 = "Draw `enter code here`text in a rectangle by passing a RectF to the DrawString method.";
using (Font font1 = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point))
{
    RectangleF rectF1 = new RectangleF(30, 10, 100, 122);
    e.Graphics.DrawString(text1, font1, Brushes.Blue, rectF1);
    e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(rectF1));
}