gpt4 book ai didi

c# - 添加到图像的文本在边缘被切断

转载 作者:行者123 更新时间:2023-12-04 16:01:23 25 4
gpt4 key购买 nike

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

如果文本太长,我需要换行。

这是我目前的代码:

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);

这是它创建的图像 Image with text overlay

如何让文字换行?

最佳答案

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

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));
}

关于c# - 添加到图像的文本在边缘被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60555424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com