打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
笔记一:画笔、笔刷认识



pen主要画线(直线、矩形、圆等)

brush主要用于填充



  1. Imports System.Drawing  
  2. Imports System.Math  
  3. Public Class Form1  
  4.     Dim gr As Graphics  
  5.     Dim pen1 As New System.Drawing.Pen(Color.Black, 3)  
  6.     Dim bp As System.Drawing.Bitmap  
  7.   
  8.     Const pi As Single = 3.14159  
  9.   
  10.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
  11.         PictureBox1.Refresh()  
  12.         pen1.DashStyle = Drawing2D.DashStyle.Dot  
  13.         pen1.Color = Color.Blue  
  14.         gr = PictureBox1.CreateGraphics  
  15.         gr.DrawLine(pen1, 0, 0, 100, 300)  
  16.   
  17.         '画椭圆  
  18.         pen1.DashStyle = Drawing2D.DashStyle.DashDotDot '重设线型  
  19.         pen1.Color = Color.BlueViolet  
  20.         gr.DrawEllipse(pen1, 10, 10, 200, 200)  
  21.         gr.Dispose()  
  22.     End Sub  
  23.   
  24.       
  25.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click  
  26.         PictureBox1.Refresh()  
  27.         pen1.Color = Color.Green  
  28.         pen1.DashStyle = Drawing2D.DashStyle.Dot  
  29.         pen1.Width = 1  
  30.   
  31.         Dim x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, r, s, t, u As Single  
  32.         For a As Single = 0 To 2 * pi Step pi / 120  
  33.             x1 = 240 + 30 * Cos(a)  
  34.             y1 = 160 + 15 * Sin(a)  
  35.             r = 60 * (1 + 1 / 6 * Sin(3 * a))  
  36.             s = 80 * (1 + 1 / 6 * Sin(4 * a))  
  37.             t = 100 * (1 + 1 / 6 * Sin(5 * a))  
  38.             u = 140 * (1 + 1 / 8 * Sin(6 * a))  
  39.             x2 = r * Cos(a + pi / 20) + 240  
  40.             y2 = r * Sin(a + pi / 20) + 160  
  41.             x3 = s * Cos(a) + 240  
  42.             y3 = s * Sin(a) + 160  
  43.             x4 = t * Cos(a + pi / 20) + 240  
  44.             y4 = t * Sin(a + pi / 20) + 160  
  45.             x5 = 1.5 * u * Cos(a) + 240  
  46.             y5 = u * Sin(a) + 160  
  47.             pen1.Color = Color.Red  
  48.             gr = PictureBox1.CreateGraphics  
  49.             gr.DrawLine(pen1, x1, y1, x2, y2)  
  50.             pen1.Color = Color.BlueViolet  
  51.             gr.DrawLine(pen1, x2, y2, x3, y3)  
  52.             pen1.Color = Color.Red  
  53.             gr.DrawLine(pen1, x3, y3, x4, y4)  
  54.             pen1.Color = Color.GreenYellow  
  55.             gr.DrawLine(pen1, x4, y4, x5, y5)  
  56.         Next  
  57.     End Sub  
  58.   
  59.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click  
  60.         'HatchBrush()        阴影笔刷  
  61.         'LinearGradientBrush   线性渐变笔刷   
  62.         'SolidBrush          单色笔刷  
  63.         'TextureBrush       纹理笔刷  
  64.         'PathGradientBrus  渐变色填充  
  65.   
  66.         '阴影笔刷(十字图案)  
  67.         Dim br1 As System.Drawing.Drawing2D.HatchBrush  
  68.         br1 = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Color.Red, Color.Black)  
  69.         gr = PictureBox1.CreateGraphics  
  70.         gr.FillEllipse(br1, 250, 0, 100, 150)  
  71.         br1.Dispose()  
  72.   
  73.         '线性渐变笔刷  
  74.         Dim br2 As System.Drawing.Drawing2D.LinearGradientBrush  
  75.         Dim p1 As New Point(140, 140) 'p1,p2控制渐变频率  
  76.         Dim p2 As New Point(160, 170)  
  77.         br2 = New System.Drawing.Drawing2D.LinearGradientBrush(p1, p2, Color.Red, Color.Black)  
  78.         gr.FillRectangle(br2, 150, 150, 100, 50)  
  79.         br2.Dispose()  
  80.   
  81.         '渐变色填充(不规则或多边形)  
  82.         Dim p(2) As Point '建立path  
  83.         p(0).X = 0 : p(0).Y = 0  
  84.         p(1).X = 20 : p(1).Y = 10  
  85.         p(2).X = 11 : p(2).Y = 22  
  86.         Dim br3 As System.Drawing.Drawing2D.PathGradientBrush  
  87.         br3 = New System.Drawing.Drawing2D.PathGradientBrush(p, Drawing.Drawing2D.WrapMode.Tile)  
  88.         br3.CenterColor = Color.Blue  '中心色  
  89.         br3.SurroundColors = New Color() {Color.Red, Color.Green, Color.Black} '边沿色对应各点数,除非是圆(一种色)  
  90.         br3.CenterPoint = New Point(11, 15) '指定中心点  
  91.         gr.FillEllipse(br3, 0, 0, 150, 100)  
  92.         br3.Dispose()  
  93.     End Sub  
  94.   
  95.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click  
  96.         PictureBox1.Refresh()  
  97.     End Sub  
  98. End Class  














仔细一看上面PathGradientBrush笔刷,发现每个不规则封闭图形中好像有“间距”,

我们放大看一下,原来,并不是间距,而是以这个不规则图外沿作为一个矩形,“平辅”到整个图形中。

添加一下辅助线,就可以清晰看出它成图的原因了:



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
VB绘制走动的表针
135均线(通达信用)源码
C#使用Graphics画圆写字
proe初学者100问 -电子-行业知识-投顶网-学习社区
怎样区别钢笔、钢笔画、钢笔画艺术的概念?
C# GDI 绘图高级编程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服