笔记3:填充图形

前端之家收集整理的这篇文章主要介绍了笔记3:填充图形前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



前面主要用pen画外形。

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


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,100,200))

        gr.FillEllipse(Brushes.Bisque,100)
        gr.FillRectangle(Brushes.Cornsilk,10,220,150,50)
        gr.FillPie(Brushes.Coral,120,80,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,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









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


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

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)

        Dim sour As New RectangleF(10,60,0.75F * bmp.Width,0.75F * bmp.Height) '原图像中取一个区域
        Dim dest As New RectangleF(180,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
原文链接:https://www.f2er.com/vb/258488.html

猜你在找的VB相关文章