我使用以下代码在图像的中心位置以一定角度绘制文本。
我需要将文本像这样铺满整张图片:我知道可以增加坐标并使用循环来实现。
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;
这将产生以下结果
如何通过准确测量绘制区域来正确地放置文本,也许有更好、更快的方法。