源自"博问",GDI+ 中如何DrawString多行文本?
我的实现方式,用数组,然后坐标定位.
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Bitmap bt1 = new Bitmap(300, 350, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bt1);
//g.DrawString(@"你好,\r\n cnblogs.com", new Font(FontFamily.GenericSansSerif, 22),
//new SolidBrush(Color.White), 32, 30, StringFormat.GenericDefault);
String[] strings = new string[] { "你好", "cnblogs.com" };
Point p = new Point(0, 0);
foreach (string s in strings)
{
p.Y = p.Y + 30;
g.DrawString(s, new Font(FontFamily.GenericSansSerif, 22),
new SolidBrush(Color.White), p.X, p.Y, StringFormat.GenericDefault);
}
bt1.Save("123.jpg", ImageFormat.Jpeg);
如有其他优化方案或解决办法,欢迎交流.
转载请注明原文地址:http://www.cnblogs.com/winzheng/archive/2009/03/05/1403992.html