Transform TextureBrush : TextureBrush « 2D Graphics « VB.Net Tutorial






Transform TextureBrush
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class TransformTextureBrush
   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 g As Graphics = Me.CreateGraphics()
        g.Clear(Me.BackColor)
        ' Create a TextureBrush object
        Dim txtrBrush As New TextureBrush(New Bitmap("yourfile.jpg"))
        ' Create a transformation matrix.
        Dim M As New Matrix
        ' Rotate the texture image by 90 degrees.
        txtrBrush.RotateTransform(90, MatrixOrder.Prepend)
        ' Translate
        M.Translate(50, 0)
        ' Multiply the transformation matrix
        ' of tBrush by translateMatrix.
        txtrBrush.MultiplyTransform(M)
        ' Scale operation
        txtrBrush.ScaleTransform(2, 1, MatrixOrder.Prepend)
        ' Fill a rectangle with texture brush
        g.FillRectangle(txtrBrush, 240, 0, 200, 200)
        ' Reset transformation
        txtrBrush.ResetTransform()
        ' Fill rectangle after reseting transformation
        g.FillRectangle(txtrBrush, 0, 0, 200, 200)
        ' Dispose
        txtrBrush.Dispose()
        g.Dispose()

  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