我写了一个图片上加字的功能,但是感觉不稳定,因为如果遇到字超出图片宽度就换行,但是换行了,但是换行的断点不正确,使得中间的几个字不见了。感觉好像有记忆或者缓存在捣乱。
而当我重新运行这些数据时,又没有这个问题了,所以很奇怪,郁闷。
if (System.Windows.Forms.TextRenderer.MeasureText(text_temp.Substring(from, j - from), f).Width > image_width)
{
from = j - 1;
image_text[hcount,0] = strtemp;
image_text[hcount,1] = height.ToString();
// imageheith[hcount] = height;
hcount++;
height = height + fontheight; } strtemp = text_temp.Substring(from, j - from); if (j == text_temp.Length)
{
image_text[hcount,0] = strtemp;
image_text[hcount,1] = height.ToString();
// imageheith[hcount] = height;
hcount++;
height = height + fontheight;
}
而当我重新运行这些数据时,又没有这个问题了,所以很奇怪,郁闷。
if (System.Windows.Forms.TextRenderer.MeasureText(text_temp.Substring(from, j - from), f).Width > image_width)
{
from = j - 1;
image_text[hcount,0] = strtemp;
image_text[hcount,1] = height.ToString();
// imageheith[hcount] = height;
hcount++;
height = height + fontheight; } strtemp = text_temp.Substring(from, j - from); if (j == text_temp.Length)
{
image_text[hcount,0] = strtemp;
image_text[hcount,1] = height.ToString();
// imageheith[hcount] = height;
hcount++;
height = height + fontheight;
}
_Graphics.DrawString("11111111111111111111", this.Font, Brushes.Red, new Rectangle(0, 0, 10, 100));真不行后面还有个参数 StringFormat ..
效果与可控性要好很多。
这个可以实现我这个需求不?
或者计算出在已指定的fontsize的高度?