笔记3:填充图形



前面主要用pen画外形。

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

笔记3:填充图形_第1张图片

Imports System.Drawing
Public Class Form1
    Dim gr As Graphics

    '填充椭圆、矩形、饼图
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim br As New System.Drawing.SolidBrush(Color.BurlyWood)
        gr = PictureBox1.CreateGraphics
        gr.FillEllipse(br, New Rectangle(0, 0, 100, 200))

        gr.FillEllipse(Brushes.Bisque, 100, 0, 100, 100)
        gr.FillRectangle(Brushes.Cornsilk, 10, 220, 150, 50)
        gr.FillPie(Brushes.Coral, 150, 120, 100, 80, 150, 120) '最后参数是在起点角度基础上增加的角度
    End Sub

    '线性渐变色
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PictureBox1.Refresh()
        Dim p1 As Point = New Point With {.X = 50, .Y = 50}
        Dim p2 As Point = New Point With {.X = 100, .Y = 200}
        Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(p1, p2, Color.Red, Color.Blue)

        gr = PictureBox1.CreateGraphics
        gr.FillRectangle(br, New Rectangle(50, 50, 50, 150))
    End Sub

    '填充闭合曲线
    '注意,与填充闭合多边形是有区别的
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        PictureBox1.Refresh()
        Dim br As New System.Drawing.SolidBrush(Color.Fuchsia)
        Dim p(3) As Point

        p(0).X = 10 : p(0).Y = 50
        p(1).X = 150 : p(1).Y = 5
        p(2).X = 100 : p(2).Y = 80
        p(3).X = 200 : p(3).Y = 200

        gr = PictureBox1.CreateGraphics
        gr.FillClosedCurve(br, p)
    End Sub
End Class









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

笔记3:填充图形_第2张图片

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

Public Class Form1
    Dim gr As Graphics

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        gr = Me.CreateGraphics
        Dim bmp As New Bitmap("D:\Movie.jpg")

        gr.DrawImage(bmp, 0, 0)

        Dim sour As New RectangleF(10, 60, 0.75F * bmp.Width, 0.75F * bmp.Height) '原图像中取一个区域
        Dim dest As New RectangleF(180, 50, 1.5F * bmp.Width, 1.5 * bmp.Height) '把上面区域,在另一个区域中绘制(放大或缩小)
        gr.DrawImage(bmp, dest, sour, GraphicsUnit.Pixel)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Refresh()
    End Sub
End Class



你可能感兴趣的:(VB.NET,填充,brush)