All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
GridView,的各种用法(4)_[Asp.Net教程]
最简单快速的Apache二级域名实现方法介绍_php资料_编程技术
php生成静态页面的简单实例_[PHP教程]
编辑web.config,保证ASP.NET的安全_.net资料_编程技术
Delphi项目的框架类-TApplication类实例-详解
精通数据库系列之入门-基础篇3_mssql学习_编程技术
操作日期的SQL语句大全_[SQL Server教程]
掌握Ajax 第1部分-Ajax简介_[AJAX教程]
ASP.NET动态网页制作初学者备忘录_.net资料_编程技术
Delphi变量、类、对象、函数规范化命名
Reading number is top 10 pictures
影评-疯子,我爱你
A man's favorite things12
男人帮杂志里的惹火性感美女1
Female model behind the bitterness, often being overcharged5
去瑜伽会所面试的经过
红楼梦金陵十二钗(1)
西游四格漫画(六)
什么叫国家
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu1
中国处女图鉴2
Download software ranking
Tram sex maniac 2 (H) rar bag9
美女游泳记
天龙八部十二宫服务端
I'm come from Beijing2
虚拟机5.5.3版
Tram sex maniac 2 (H) rar bag12
变速齿轮3.26
Boxer Classic video3
Boxer's Top ten classic battle4
C++编程教程第三版
qq published in(发表于) 2014/7/11 9:16:55 Edit(编辑)
c#中GDI+图形图像:用直线和曲线消除锯齿

c#中GDI+图形图像:用直线和曲线消除锯齿

c#中GDI+图形图像:用直线和曲线消除锯齿

用直线和曲线消除锯齿

1.用直线消除锯齿

用基本的DrawLine方法绘制出来的直线看上去带有锯齿,有点像楼梯,这种用楼梯状来表示直线的技术被称为锯齿化,楼梯是理论直线的一个别名。

一项更为复杂的呈现直线的技术需要使用部分透明的像素和不透明的像素,而这种呈现方式被称为消除锯齿,它可以生成视觉上更平滑的直线。消除锯齿需要使用Graphics类的SmoothingMode属性,该属性属于System.Drawing.Drawing2D命名空间,它主要用来获取或设置Graphics图像的呈现质量,其属性值及说明如表1所示。



表1 SmoothingMode属性值及说明

示例

用直线消除锯齿

本示例中,当程序运行时,单击【原图】按钮,调用DrawLine方法绘制一条直线,然后单击【直线消除锯齿】按钮,在窗体中绘制一条经过消除锯齿的直线,比较它们的呈现效果。示例运行结果如图1所示。



图1 用直线消除锯齿

Form1窗体中,单击【直线消除锯齿】按钮,调用Graphics对象的DrawLine方法在窗体中绘制一条直线,并通过设置Graphics对象的SmoothingMode属性,对绘制的直线进行消除锯齿操作。网站源代码【直线消除锯齿】按钮的Click事件代码如下:

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

Pen myPen = new Pen(Color.Blue, 2);

graphics.SmoothingMode = SmoothingMode.AntiAlias;

graphics.DrawLine(myPen, 140, 40, 220, 40);

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace _6_15

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

Pen myPen = new Pen(Color.Blue, 2);

graphics.SmoothingMode = SmoothingMode.AntiAlias;

graphics.DrawLine(myPen, 140, 40, 220, 40);

}

private void button2_Click(object sender, EventArgs e)

{//本教程来自:HTTP://www.isstudy.com

Graphics graphics = this.CreateGraphics();

Pen myPen = new Pen(Color.Blue, 2);

graphics.DrawLine(myPen, 40, 40, 120, 40);

}

}

}

★ ★★★★Form1.Designer.cs窗体设计文件完整程序代码★★★★★

namespace _6_15

{

partial class Form1

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(138, 70);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(90, 23);

this.button1.TabIndex = 0;

this.button1.Text = "直线消除锯齿";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

//本教程来自:HTTP://www.isstudy.com

// button2

//

this.button2.Location = new System.Drawing.Point(44, 70);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(75, 23);

this.button2.TabIndex = 1;

this.button2.Text = "原图";

this.button2.UseVisualStyleBackColor = true;


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.