本文主要是介绍C#中GDI绘制高质量平滑图形实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
protected override void OnPaint(PaintEventArgs e)
{
try
{
Graphics g = e.Graphics;//获取绘制对象
///设置参数
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //图片柔顺模式选择
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;//高质量
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;//再加一点
int topheight = 30;
//绘制Title标题 ----//填充区域
g.FillRectangle(new SolidBrush(Color.FromArgb(223, 221, 216)), 0, 0, Width, topheight);
绘制标题
int numw = (int)g.MeasureString("新建窗体", Font).Width;
int numh = (int)g.MeasureString("新建窗体", Font).Height;
g.DrawString("新建窗体", Font, new SolidBrush(Color.FromArgb(100, 99, 94)), new PointF(topheight, topheight / 2 - numh / 2));
//绘制窗体中间的文字
Font font = new Font(Font.FontFamily, 12, FontStyle.Bold);
int numx = (int)g.MeasureString(Text, font).Width;
int numy = (int)g.MeasureString(Text, font).Height;
g.DrawString(Text, font, new SolidBrush(Color.FromArgb(178, 34, 34)), new PointF(Width / 2 - numx / 2, topheight / 2 - numy / 2));
// g.DrawImage(Properties.Resources.logo128, 10, 8, 16, 16);
}
catch
{
this.Invalidate();
}
}
这篇关于C#中GDI绘制高质量平滑图形实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!