打开APP
userphoto
未登录

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

开通VIP
笔记3:填充图形



前面主要用pen画外形。

下面用brush来填充图形,填充根据笔刷的不同而不同。


  1. Imports System.Drawing  
  2. Public Class Form1  
  3.     Dim gr As Graphics  
  4.   
  5.     '填充椭圆、矩形、饼图  
  6.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
  7.         Dim br As New System.Drawing.SolidBrush(Color.BurlyWood)  
  8.         gr = PictureBox1.CreateGraphics  
  9.         gr.FillEllipse(br, New Rectangle(0, 0, 100, 200))  
  10.   
  11.         gr.FillEllipse(Brushes.Bisque, 100, 0, 100, 100)  
  12.         gr.FillRectangle(Brushes.Cornsilk, 10, 220, 150, 50)  
  13.         gr.FillPie(Brushes.Coral, 150, 120, 100, 80, 150, 120) '最后参数是在起点角度基础上增加的角度  
  14.     End Sub  
  15.   
  16.     '线性渐变色  
  17.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click  
  18.         PictureBox1.Refresh()  
  19.         Dim p1 As Point = New Point With {.X = 50, .Y = 50}  
  20.         Dim p2 As Point = New Point With {.X = 100, .Y = 200}  
  21.         Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(p1, p2, Color.Red, Color.Blue)  
  22.   
  23.         gr = PictureBox1.CreateGraphics  
  24.         gr.FillRectangle(br, New Rectangle(50, 50, 50, 150))  
  25.     End Sub  
  26.   
  27.     '填充闭合曲线  
  28.     '注意,与填充闭合多边形是有区别的  
  29.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click  
  30.         PictureBox1.Refresh()  
  31.         Dim br As New System.Drawing.SolidBrush(Color.Fuchsia)  
  32.         Dim p(3) As Point  
  33.   
  34.         p(0).X = 10 : p(0).Y = 50  
  35.         p(1).X = 150 : p(1).Y = 5  
  36.         p(2).X = 100 : p(2).Y = 80  
  37.         p(3).X = 200 : p(3).Y = 200  
  38.   
  39.         gr = PictureBox1.CreateGraphics  
  40.         gr.FillClosedCurve(br, p)  
  41.     End Sub  
  42. End Class  









随便认识一下图像的绘制。


注意:原图(左)中的一部分,在右绘制时,是放大了的。

  1. Public Class Form1  
  2.     Dim gr As Graphics  
  3.   
  4.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
  5.         gr = Me.CreateGraphics  
  6.         Dim bmp As New Bitmap("D:\Movie.jpg")  
  7.   
  8.         gr.DrawImage(bmp, 0, 0)  
  9.   
  10.         Dim sour As New RectangleF(10, 60, 0.75F * bmp.Width, 0.75F * bmp.Height) '原图像中取一个区域  
  11.         Dim dest As New RectangleF(180, 50, 1.5F * bmp.Width, 1.5 * bmp.Height) '把上面区域,在另一个区域中绘制(放大或缩小)  
  12.         gr.DrawImage(bmp, dest, sour, GraphicsUnit.Pixel)  
  13.     End Sub  
  14.   
  15.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click  
  16.         Me.Refresh()  
  17.     End Sub  
  18. End Class  



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# GDI 使用操作、入门解析
Byte Array to String
C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
详解C#数据库存取图片三大方式 -IT168 技术开发专区
数字图像处理 C# 程序代码实例
vb.net GDI 入门——创建 Graphics 对象
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服