GDI画图时的锯齿效果弱化
2014-12-12 20:31
162 查看
GDI画图时的锯齿效果弱化
当在画图时,图形有时会出现锯齿,可以使用SmoothingMode.AntiAlias来消除
代码如下:
g.SmoothingMode = SmoothingMode.AntiAlias;
使图像的边缘圆滑清晰锐化的可以试试FillPath
代码如下
针对于文本锯齿的话,可以采用TextRenderingHint
代码如下
SolidBrush brush = new SolidBrush(Color.Green);
e.Graphics.DrawString("ABCDEFGHIJKL", new Font("宋体", 15f), brush, 0, 20);
//消除锯齿
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
e.Graphics.DrawString("ABCDEFGHIJKL", new Font("宋体", 15f), brush, 0, 50);
有时候使用Graphics.Clear()方法,会在图像上出现颗粒型的点,尽量不要采用Graphics.Clear()来填充区域,一般使用Graphics.FillPath();
有兴趣的可以尝试下下面的代码:
public Form11()
{
InitializeComponent();
this.BackColor = Color.Black;
Method();
this.Paint += Draw;
}
Bitmap bitmap1;
private void Draw(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(bitmap1, 0, 0);
e.Graphics.DrawString("ABCDEFGHIJKL", new Font("宋体", 15f), new SolidBrush(Color.Green), 0, 50);
}
private void Method()
{
bitmap1 = new Bitmap(500, 500);
Graphics g = Graphics.FromImage(bitmap1);
GraphicsPath path = new GraphicsPath();
//g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
//g.CompositingMode = CompositingMode.SourceCopy;
//g.TextRenderingHint = TextRenderingHint.AntiAlias;
int alpha = 1;
for (int i = 20; i > 2; i--)
{
path.Reset();
path.AddEllipse(20, 20, 50, 50);
path.Widen(new Pen(Color.Black, i));
g.SetClip(path);
//g.Clear(Color.Black); // wrong
g.ResetClip();
//g.FillPath((Brushes.Black), path); // right
g.FillPath(new SolidBrush(Color.FromArgb(alpha += 10, 255, 255, 255)), path);
}
}
GDI画图时的锯齿效果弱化
当在画图时,图形有时会出现锯齿,可以使用SmoothingMode.AntiAlias来消除
代码如下:
g.SmoothingMode = SmoothingMode.AntiAlias;
使图像的边缘圆滑清晰锐化的可以试试FillPath
代码如下
g.FillPath((Brushes.Black), path);或者是
针对于文本锯齿的话,可以采用TextRenderingHint
代码如下
SolidBrush brush = new SolidBrush(Color.Green);
e.Graphics.DrawString("ABCDEFGHIJKL", new Font("宋体", 15f), brush, 0, 20);
//消除锯齿
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
e.Graphics.DrawString("ABCDEFGHIJKL", new Font("宋体", 15f), brush, 0, 50);
有时候使用Graphics.Clear()方法,会在图像上出现颗粒型的点,尽量不要采用Graphics.Clear()来填充区域,一般使用Graphics.FillPath();
有兴趣的可以尝试下下面的代码:
public Form11()
{
InitializeComponent();
this.BackColor = Color.Black;
Method();
this.Paint += Draw;
}
Bitmap bitmap1;
private void Draw(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(bitmap1, 0, 0);
e.Graphics.DrawString("ABCDEFGHIJKL", new Font("宋体", 15f), new SolidBrush(Color.Green), 0, 50);
}
private void Method()
{
bitmap1 = new Bitmap(500, 500);
Graphics g = Graphics.FromImage(bitmap1);
GraphicsPath path = new GraphicsPath();
//g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
//g.CompositingMode = CompositingMode.SourceCopy;
//g.TextRenderingHint = TextRenderingHint.AntiAlias;
int alpha = 1;
for (int i = 20; i > 2; i--)
{
path.Reset();
path.AddEllipse(20, 20, 50, 50);
path.Widen(new Pen(Color.Black, i));
g.SetClip(path);
//g.Clear(Color.Black); // wrong
g.ResetClip();
//g.FillPath((Brushes.Black), path); // right
g.FillPath(new SolidBrush(Color.FromArgb(alpha += 10, 255, 255, 255)), path);
}
}
相关文章推荐
- html5 canvas 画图移动端出现锯齿毛边的解决方法
- 手机端页面:抗锯齿和快速滚动和回弹效果
- GDI画图的几种方式(小游戏不闪烁)
- android surfaceView 的简单使用 画图,拖动效果
- 安卓利用shpae画图,用XML文件做出渐变的效果
- win32 GDI 画图
- C#中使用GDI画图工具动态显示
- GDI_图片半透明效果示例
- 用javascript实现画图效果的代码
- MFC 双缓冲 GDI+ Graphics 在图片上画图写字 避免闪烁
- JAVA画图中反锯齿
- 孙鑫VC学习笔记:第十讲画图 创建设置画笔的对话框 并且可以预览效果
- 孙鑫VC学习笔记:第十讲画图 创建设置画笔的对话框 并且可以预览效果
- Windows GDI图形接口的严重问题:效率低下造成图形横向移动时出现阶梯状锯齿
- Unity 画图效果
- D2D引擎与GDI\GDI+绘制效果对比
- 用javascript实现画图效果的代码
- Android画图之抗锯齿
- GDI 画图问题集锦
- 通过画图实现动画效果