当前位置: 首页 > news >正文

网站建设岗位内容自己如何注册网站

网站建设岗位内容,自己如何注册网站,个人旅游网站模版,做公司网站客户群体怎么找在 C# 中,Graphics 类是 System.Drawing 命名空间的一部分,它提供了一组方法和属性,用于在 Windows Forms 应用程序中进行二维绘图。Graphics 对象可以绘制文本、线条、曲线、形状和图像,并可以对它们进行变换和剪辑。 Graphics …

在 C# 中,Graphics 类是 System.Drawing 命名空间的一部分,它提供了一组方法和属性,用于在 Windows Forms 应用程序中进行二维绘图。Graphics 对象可以绘制文本、线条、曲线、形状和图像,并可以对它们进行变换和剪辑。

Graphics 类的一些常用功能和方法: 

1.绘制线条

DrawLine(Pen pen, int x1, int y1, int x2, int y2):使用指定的 Pen 对象绘制直线。

DrawLines(Pen pen, Point[] points):使用指定的 Pen 对象和点数组绘制一系列连续的线条。

public Form1()
{InitializeComponent();this.panel1.Paint += Panel1_Paint;this.panel2.Paint += Panel2_Paint;
}
//DrawLine(Pen pen, int x1, int y1, int x2, int y2)
private void Panel1_Paint(object sender, PaintEventArgs e)
{//1.创建图形(画布,画板)Graphics g = e.Graphics;//2.设置绘制参数()SetQuality(g);//3.开始绘制Pen pen = new Pen(Color.Red, 10F);Point pt1 = new Point(50, 50);Point pt2 = new Point(100, 50);g.DrawLine(pen, pt1, pt2);//注意:起点的坐标,考虑画笔的宽度Pen pen1 = new Pen(Color.Blue, 10F);Point pt3 = new Point(100 + 5, 50 - 5);Point pt4 = new Point(100 + 5, 100);g.DrawLine(pen1, pt3, pt4);
}
//DrawLines(Pen pen, Point[] points)
private void Panel1_Paint(object sender, PaintEventArgs e)
{Pen pen = new Pen(Color.Red, 10F);Point[] points = new Point[]{new Point(80,150),new Point(80,20),new Point(20,100),new Point(120,100),};g.DrawLines(pen, points);
}

2.绘制形状: 

DrawRectangle(Pen pen, int x, int y, int width, int height):使用指定的 Pen 对象绘制矩形。

DrawEllipse(Pen pen, int x, int y, int width, int height):使用指定的 Pen 对象绘制椭圆。

DrawPolygon(Pen pen, Point[] points):使用指定的 Pen 对象和点数组绘制多边形。

public Form1()
{InitializeComponent();this.panel1.Paint += Panel1_Paint;this.panel2.Paint += Panel2_Paint;this.panel3.Paint += Panel3_Paint;
}
//矩形DrawRectangle(Pen pen, int x, int y, int width, int height)
private void Panel1_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);Pen pen1 = new Pen(Color.Red, 10F);Rectangle rect = new Rectangle(20,20,100,100);g.DrawRectangle(pen1, rect);
}
//椭圆DrawEllipse(Pen pen, int x, int y, int width, int height)
private void Panel2_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);Pen pen1 = new Pen(Color.Red, 10F);Rectangle rect = new Rectangle(20,20,80,100);g.DrawEllipse(pen1, rect);//椭圆
}
//多边形DrawPolygon(Pen pen, Point[] points)
private void Panel3_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);Pen pen1 = new Pen(Color.Red, 10F);Point[] points = new Point[]{new Point(80,20),new Point(20,100),new Point(120,100),};g.DrawPolygon(pen1, points);
}

 3.填充形状

FillRectangle(Brush brush, int x, int y, int width, int height):使用指定的 Brush 对象填充矩形。

FillEllipse(Brush brush, int x, int y, int width, int height):使用指定的 Brush 对象填充椭圆。

FillPolygon(Brush brush, Point[] points):使用指定的 Brush 对象填充多边形。

public Form1()
{InitializeComponent();this.panel1.Paint += Panel1_Paint;this.panel2.Paint += Panel2_Paint;this.panel3.Paint += Panel3_Paint;
}
//FillRectangle(Brush brush, int x, int y, int width, int height)
private void Panel1_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);Pen pen1 = new Pen(Color.Red, 10F);Rectangle rect = new Rectangle(20,20,100,100);Brush brush = new SolidBrush(Color.Yellow);g.FillRectangle(brush, rect);g.DrawRectangle(pen1, rect);//矩形
}
//FillEllipse(Brush brush, int x, int y, int width, int height)
private void Panel2_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);Pen pen1 = new Pen(Color.Red, 10F);Rectangle rect = new Rectangle(20,20,80,100);Brush brush = new SolidBrush(Color.Yellow);g.FillEllipse(brush, rect);g.DrawEllipse(pen1, rect);//椭圆
}
//FillPolygon(Brush brush, Point[] points)
private void Panel3_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);Pen pen1 = new Pen(Color.Red, 10F);Point[] points = new Point[]{new Point(80,20),new Point(20,100),new Point(120,100),};Brush brush = new SolidBrush(Color.Yellow);g.DrawPolygon(pen1, points);g.FillPolygon(brush,points);
}

4.绘制文本: 

DrawString(String s, Font font, Brush brush, float x, float y):在指定位置绘制文本字符串。

public Form1()
{InitializeComponent();this.panel1.Paint += Panel1_Paint;
}private void Panel1_Paint(object sender, PaintEventArgs e){Graphics g = e.Graphics;SetQuality(g);string s = "相寻梦里路,飞雨落花中";Font font = new Font("华文琥珀",20F);Brush brush  = new SolidBrush(Color.Pink);g.DrawString(s,font,brush,10,10);}

5.图像处理

DrawImage(Image image, Point point):在指定位置绘制图像。

DrawImage(Image image, Rectangle rect):在指定矩形区域内绘制图像。

public Form1()
{InitializeComponent();this.panel1.Paint += Panel1_Paint;this.panel1.Paint += Panel2_Paint;
}        
private void Panel1_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);string path = Path.Combine(Environment.CurrentDirectory, "../../image/1.png");Image img = Image.FromFile(path);Point point = new Point( 0, 0);g.DrawImage(img, point);//在指定位置绘制图像img.Dispose(); // 释放图像资源
}
private void Panel2_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g);string path = Path.Combine(Environment.CurrentDirectory, "../../image/2.png");Image img = Image.FromFile(path);Rectangle rect = new Rectangle(0,0,300,240);g.DrawImage(img, rect);img.Dispose(); // 释放图像资源
}

 

6.变换和剪辑: 

TranslateTransform(float dx, float dy):对当前的坐标系统进行平移变换。

ScaleTransform(float sx, float sy):对当前的坐标系统进行缩放变换。

RotateTransform(float angle):对当前的坐标系统进行旋转变换。

SetClip(Rectangle rect):设置当前的剪辑区域。

代码在下面

1.平移变换                         2.缩放变换                        3. 旋转变换         

 

 7.获取信息

VisibleClipBounds:获取当前剪辑区域的边界。

IsVisible(Point point):判断一个点是否在可见区域内。

代码

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
namespace 图形变换和剪辑
{public partial class Form1 : Form{public Form1(){InitializeComponent();Panel panel1 = new Panel{Size = new Size(400, 400),Location = new Point(50, 50),BackColor = Color.Green,};this.Controls.Add(panel1);panel1.Paint += Panel1_Paint; 平移变换panel1.Paint += Panel2_Paint; // 缩放变换panel1.Paint += Panel3_Paint; // 旋转变换panel1.Paint += Panel4_Paint; // 设置剪辑区域}private void Panel1_Paint(object sender, PaintEventArgs e){Graphics g = e.Graphics;SetQuality(g);string path = Path.Combine(Environment.CurrentDirectory, "../../image/1.png");Image img = Image.FromFile(path);g.TranslateTransform(100, 0);g.DrawImage(img, new Point(0,0));}private void Panel2_Paint(object sender, PaintEventArgs e){Graphics g = e.Graphics;SetQuality(g);string path = Path.Combine(Environment.CurrentDirectory, "../../image/1.png");Image img = Image.FromFile(path);g.ScaleTransform(1.5F,1.5F);//缩放g.DrawImage(img, new Point(-100, -100));}private void Panel3_Paint(object sender, PaintEventArgs e){Graphics g = e.Graphics;SetQuality(g);string path = Path.Combine(Environment.CurrentDirectory, "../../image/1.png");Image img = Image.FromFile(path);g.RotateTransform(45); // 旋转变换g.DrawImage(img, new Point(0, 0));}private void Panel4_Paint(object sender, PaintEventArgs e){Graphics g = e.Graphics;SetQuality(g);string path = Path.Combine(Environment.CurrentDirectory, "../../image/2.png");Image img = Image.FromFile(path);Rectangle clipRect = new Rectangle(50, 50, 300, 300);g.SetClip(clipRect);//设置当前编辑区// 获取信息RectangleF visibleClipBounds = g.VisibleClipBounds;Console.WriteLine($"Visible Clip Bounds: {visibleClipBounds}");Point testPoint = new Point(100, 100);bool isVisible = g.IsVisible(testPoint);Console.WriteLine($"Point {testPoint} is visible: {isVisible}");}private static void SetQuality(Graphics g){g.SmoothingMode = SmoothingMode.AntiAlias;g.CompositingQuality = CompositingQuality.HighQuality;g.InterpolationMode = InterpolationMode.HighQualityBicubic;}}
}

SetQuality()

SetQuality 方法是一个自定义方法,它不是 System.Drawing 命名空间的一部分。这个方法通常用于设置 Graphics 对象的属性,以提高绘制质量,特别是在进行图形变换、绘制文本或图像时。

SetQuality 方法设置了以下几个关键属性:

  1. SmoothingMode:设置为 SmoothingMode.AntiAlias,以启用抗锯齿,使线条和曲线更平滑。
  2. InterpolationMode:设置为 InterpolationMode.HighQualityBicubic,以在图像缩放时使用高质量的双三次插值算法。
  3. PixelOffsetMode:设置为 PixelOffsetMode.HighQuality,以减少图像旋转和大字体文本时的像素偏移。
  4. TextRenderingHint:设置为 TextRenderingHint.AntiAliasGridFit,以提高文本渲染的质量和清晰度。
  5. CompositingQuality:设置为 CompositingQuality.HighQuality,以确保在合成图像时使用高质量的算法。
using System.Drawing;
using System.Drawing.Drawing2D;
public void SetQuality(Graphics g)
{// 设置高质量渲染模式g.SmoothingMode = SmoothingMode.AntiAlias; // 抗锯齿// 设置高质量的插值模式g.InterpolationMode = InterpolationMode.HighQualityBicubic; // 高质量双三次插值// 设置高质量的像素偏移模式g.PixelOffsetMode = PixelOffsetMode.HighQuality; // 高质量像素偏移// 设置高质量的路径渐变g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; // 文本抗锯齿// 设置图形对象的线性变换和旋转变换的精度g.CompositingQuality = CompositingQuality.HighQuality; // 高质量合成
}// 在 Paint 事件处理程序中使用 SetQuality 方法
private void MyControl_Paint(object sender, PaintEventArgs e)
{Graphics g = e.Graphics;SetQuality(g); // 应用高质量设置// 现在使用 g 绘制文本、线条、形状等g.DrawString("Hello, World!", new Font("Arial", 16), Brushes.Black, new PointF(10, 10));
}


文章转载自:
http://dinncoteleconferencing.zfyr.cn
http://dinncodenuclearize.zfyr.cn
http://dinncohg.zfyr.cn
http://dinncobachelor.zfyr.cn
http://dinncointerblend.zfyr.cn
http://dinncotophus.zfyr.cn
http://dinncosinaean.zfyr.cn
http://dinncoknopkierie.zfyr.cn
http://dinncorhenium.zfyr.cn
http://dinncostruvite.zfyr.cn
http://dinncopedosphere.zfyr.cn
http://dinncoheterotopia.zfyr.cn
http://dinncosymbiosis.zfyr.cn
http://dinncoincuse.zfyr.cn
http://dinncosurcoat.zfyr.cn
http://dinncopracticant.zfyr.cn
http://dinncounweary.zfyr.cn
http://dinncosubline.zfyr.cn
http://dinncoaria.zfyr.cn
http://dinncoectrodactyly.zfyr.cn
http://dinncomisemploy.zfyr.cn
http://dinncosladang.zfyr.cn
http://dinncomatriliny.zfyr.cn
http://dinncoartistically.zfyr.cn
http://dinncoprospectus.zfyr.cn
http://dinncocalyculus.zfyr.cn
http://dinncoliterate.zfyr.cn
http://dinncopitcher.zfyr.cn
http://dinncooviparous.zfyr.cn
http://dinncopraxis.zfyr.cn
http://dinnconoctilucent.zfyr.cn
http://dinncoreunification.zfyr.cn
http://dinncosyllabarium.zfyr.cn
http://dinncoteleplay.zfyr.cn
http://dinncogenf.zfyr.cn
http://dinncocoprecipitation.zfyr.cn
http://dinncohortensia.zfyr.cn
http://dinncobagwig.zfyr.cn
http://dinncolactescence.zfyr.cn
http://dinncosemiarc.zfyr.cn
http://dinncotaciturnly.zfyr.cn
http://dinncodeadneck.zfyr.cn
http://dinncotableware.zfyr.cn
http://dinncoxanthosis.zfyr.cn
http://dinncofeuilletonist.zfyr.cn
http://dinncopostrorse.zfyr.cn
http://dinncoentity.zfyr.cn
http://dinncomether.zfyr.cn
http://dinncoappulsive.zfyr.cn
http://dinncolickspit.zfyr.cn
http://dinncohexahydrothymol.zfyr.cn
http://dinncowinner.zfyr.cn
http://dinncosubfuscous.zfyr.cn
http://dinncomitogenic.zfyr.cn
http://dinncochloridize.zfyr.cn
http://dinncoballoonfish.zfyr.cn
http://dinncobpi.zfyr.cn
http://dinnconucellar.zfyr.cn
http://dinncounceasingly.zfyr.cn
http://dinnconbs.zfyr.cn
http://dinncohexahydrothymol.zfyr.cn
http://dinncoknickerbockers.zfyr.cn
http://dinncokc.zfyr.cn
http://dinncokatanga.zfyr.cn
http://dinncocephalous.zfyr.cn
http://dinncosharkskin.zfyr.cn
http://dinncoliteralism.zfyr.cn
http://dinncocombinative.zfyr.cn
http://dinncobryophyte.zfyr.cn
http://dinncovolleyfire.zfyr.cn
http://dinncoceramide.zfyr.cn
http://dinncomisoneism.zfyr.cn
http://dinncocrop.zfyr.cn
http://dinncoantistrophe.zfyr.cn
http://dinncocontrapposto.zfyr.cn
http://dinncokil.zfyr.cn
http://dinncosab.zfyr.cn
http://dinncoremora.zfyr.cn
http://dinncoribaldly.zfyr.cn
http://dinncoarchetypal.zfyr.cn
http://dinncotangleberry.zfyr.cn
http://dinncoplaza.zfyr.cn
http://dinncoailurophobia.zfyr.cn
http://dinncobenign.zfyr.cn
http://dinncoundeviating.zfyr.cn
http://dinncoguttle.zfyr.cn
http://dinncovilleggiatura.zfyr.cn
http://dinncoadvise.zfyr.cn
http://dinnconoil.zfyr.cn
http://dinncotantalizing.zfyr.cn
http://dinncoyearling.zfyr.cn
http://dinncoignitor.zfyr.cn
http://dinncocolumnist.zfyr.cn
http://dinncoglycosyl.zfyr.cn
http://dinncotoulon.zfyr.cn
http://dinncotangible.zfyr.cn
http://dinncopaedobaptist.zfyr.cn
http://dinncoparaplegic.zfyr.cn
http://dinncolacunar.zfyr.cn
http://dinncokeddah.zfyr.cn
http://www.dinnco.com/news/115274.html

相关文章:

  • .net网站与php网站江苏百度推广代理商
  • vr技术在网站建设的应用百度客服电话4001056
  • wordpress 开店京东seo搜索优化
  • 网站链接提交百度软件中心官网
  • 冒充it男给某网站做修复有哪些营销推广方式
  • qq音乐如何做mp3下载网站郑州疫情最新动态
  • 国内专门做酒的网站自助建站系统
  • 学校门户网站建设的意义游戏代理
  • 公司网站建立流程新发布的新闻
  • 网站关键词方案今日资讯最新消息
  • 专业网站建设公司 1861web湖北疫情最新情况
  • 网站建设服务公司有用吗深圳网站设计公司
  • 日本做网站电脑优化大师下载安装
  • 03340网站建设与管理沈阳专业seo关键词优化
  • 网站目录程序sem培训
  • 国外做家谱的网站域名备案官网
  • 网站需要多大空间元搜索引擎有哪些
  • 网站的收藏本站怎么做电子商务网站建设的步骤
  • 济南网站优化分析可以免费做网站推广的平台
  • 专题网站策划书深圳新闻最新事件
  • 用react做的网站上传关键词优化哪个好
  • 互联网行业怎么样杭州百度seo优化
  • jsp asp php哪个做网站乐陵seo外包
  • 网站数据流分析怎么做企业线上培训课程
  • 手机网站关键词排名查询搜索引擎优化关键词
  • 企业网站做多大尺寸广州网站建设公司
  • 安徽池州做企业网站购物网站页面设计
  • 分类信息网站 建议 建设长沙百度seo
  • 网站编程技术 吉林出版集团股份有限公司建立自己的网站
  • 做app要不要建网站stp营销战略