Generate points to draw a star shape : TextureBrush « 2D Graphics « VB.Net Tutorial






Generate points to draw a star shape
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Math

public class DrawAStarShape
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

public class Form1
  Inherits System.Windows.Forms.Form

  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        '
        Dim cx As Integer = Me.ClientSize.Width \ 2
        Dim cy As Integer = Me.ClientSize.Height \ 2
        Dim r1 As Integer = Min(cx, cy) - 10
        Dim r2 As Integer = Min(cx, cy) \ 2
        Dim pts(9) As Point
        For i As Integer = 0 To 9 Step 2
            pts(i).X = cx + CInt(r1 * Cos(i * PI / 5 - PI / 2))
            pts(i).Y = cy + CInt(r1 * Sin(i * PI / 5 - PI / 2))
            pts(i + 1).X = cx + CInt(r2 * Cos((i + 1) * PI / 5 - PI / 2))
            pts(i + 1).Y = cy + CInt(r2 * Sin((i + 1) * PI / 5 - PI / 2))
        Next i

        Dim texture_brush As New TextureBrush(new Bitmap("yourfile.jpg"))

        e.Graphics.FillPolygon(texture_brush, pts)
        e.Graphics.DrawPolygon(Pens.Black, pts)
  End Sub

  Public Sub New()
   
    MyBase.New()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

  End Sub

End Class








17.65.TextureBrush
17.65.1.Create textured brush and display textured rectangleCreate textured brush and display textured rectangle
17.65.2.Create TextureBrush from BitmapCreate TextureBrush from Bitmap
17.65.3.Generate points to draw a star shapeGenerate points to draw a star shape
17.65.4.Transform and Rotate the TextureBrushTransform and Rotate the TextureBrush
17.65.5.Transform TextureBrushTransform TextureBrush