【发布时间】:2016-12-04 00:57:43
【问题描述】:
我使用下面的代码在图像的中心绘制一个角度的文本
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));
}
我需要像这样将文字平铺在图像上
我知道我可以增加坐标并使用循环。我有
Bitmap bmp = new Bitmap(pictureBox1.Image);
for (int i = 0; i < bmp.Width; i += 20)
{
for (int y = 0; y < bmp.Height; y += 20)
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
g.RotateTransform(30);
SizeF textSize = g.MeasureString("my test image", DefaultFont);
g.DrawString("my test image", DefaultFont, Brushes.Yellow, i, y);
}
}
}
pictureBox1.Image = bmp;
这会产生以下结果
如何通过正确测量绘制区域来正确放置文本。可能是更好更快的方法。
【问题讨论】:
-
您是每次都添加相同的文本还是完全是动态的?
标签: c# .net bitmap gdi+ system.drawing