Click here to Skip to main content
13,667,414 members
Click here to Skip to main content
Articles » Multimedia » GDI+ » General » Downloads

Stats

335K views
11K downloads
184 bookmarked
Posted 13 Sep 2004
Licenced CPOL

Matrix Transformation of Images using .NET GDI+

, 1 Jul 2016
Use of GDI+ Matrix class to perform image transformation.
Transformation
App.ico
Transformation.csproj.user
Transformation.suo
bin
Release
Transformation.exe
obj
Interop.VBEthnic.dll
Debug
Transformation.projdata
Release
Transformation.exe
Transformation.Form1.resources
Transformation.projdata
App.ico
Transformation.csproj.user
Transformation.exe
Interop.VBEthnic.dll
App.ico
Debug
Transformation.Form1.resources
Transformation.Form2.resources
Transformation.Form1.resources
Transformation.csproj.user
Transformation.suo
UpgradeLog.XML
App.ico
Transformation.csproj.user
Transformation.suo
UpgradeLog.XML
Transformation.exe
Transformation.pdb
Transformation.vshost.exe
Interop.VBEthnic.dll
Transformation.csproj.GenerateResource.Cache
Transformation.exe
Transformation.Form1.resources
Transformation.Form2.resources
Transformation.pdb
Transformation.csproj.GenerateResource.Cache
Transformation.exe
Transformation.Form1.resources
Transformation.exe
App.ico
Transformation.exe
Transformation.pdb
Transformation.vshost.exe
TempPE
Transformation.csproj.GenerateResource.Cache
Transformation.exe
Transformation.Form1.resources
Transformation.Form2.resources
Transformation.pdb
Interop.VBEthnic.dll
Transformation.csproj.GenerateResource.Cache
Transformation.exe
Transformation.Form1.resources
Transformation.csproj.user
Transformation.suo
UpgradeLog.XML
Transformation
bin
Debug
Transformation.exe
Transformation.pdb
Transformation.vshost.exe
My Project
Application.myapp
obj
Debug
Resources.resources
TempPE
My Project.Resources.Designer.vb.dll
Transformation.exe
Transformation.Form1.resources
Transformation.pdb
Transformation.vbproj.GenerateResource.Cache
Transformation.vbproj.user
Transformation.suo
Transformation.suo
Transformation.vbproj.user
Transformation.pdb
Application.myapp
Resources.resources
Transformation.Form1.resources
Transformation.pdb
Transformation.vbproj.GenerateResource.Cache
Transformation.suo
Transformation.vbproj.user
Transformation.exe
Transformation.pdb
Transformation.vshost.exe
Application.myapp
Resources.resources
Transformation.exe
Transformation.Form1.resources
Transformation.pdb
Transformation.vbproj.GenerateResource.Cache
My Project.Resources.Designer.vb.dll
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging


Namespace Transformation
	''' <summary>
	''' Summary description for Form1.
	''' </summary>
	Public Class Form1
		Inherits System.Windows.Forms.Form
		Private pictureBox1 As System.Windows.Forms.PictureBox
        Private WithEvents button1 As System.Windows.Forms.Button
		Private listBox1 As System.Windows.Forms.ListBox
		Private label2 As System.Windows.Forms.Label
        Private WithEvents tRotDeg As System.Windows.Forms.TrackBar
		Private lblRotDeg As System.Windows.Forms.Label
        Private WithEvents cbRotate As System.Windows.Forms.CheckBox
		Private label3 As System.Windows.Forms.Label
		Private lblTransX As System.Windows.Forms.Label
        Private WithEvents tTransX As System.Windows.Forms.TrackBar
		Private label5 As System.Windows.Forms.Label
		Private lblTransY As System.Windows.Forms.Label
        Private WithEvents tTransY As System.Windows.Forms.TrackBar
		Private label9 As System.Windows.Forms.Label
		Private lblRotY As System.Windows.Forms.Label
        Private WithEvents tRotY As System.Windows.Forms.TrackBar
		Private label11 As System.Windows.Forms.Label
		Private lblRotX As System.Windows.Forms.Label
        Private WithEvents tRotX As System.Windows.Forms.TrackBar
		Private label14 As System.Windows.Forms.Label
		Private lblStrY As System.Windows.Forms.Label
        Private WithEvents tStrY As System.Windows.Forms.TrackBar
        Private WithEvents cbStretch As System.Windows.Forms.CheckBox
		Private label16 As System.Windows.Forms.Label
		Private lblStrX As System.Windows.Forms.Label
        Private WithEvents tStrX As System.Windows.Forms.TrackBar
        Private WithEvents buttonDown As System.Windows.Forms.Button
        Private WithEvents buttonUp As System.Windows.Forms.Button
        Private WithEvents cbTranslation As System.Windows.Forms.CheckBox
		Private pictureBoxBase As System.Windows.Forms.PictureBox
        Private WithEvents cbFlipY As System.Windows.Forms.CheckBox
        Private WithEvents btnReset As System.Windows.Forms.Button
        Private WithEvents cbRealtime As System.Windows.Forms.CheckBox
		''' <summary>
		''' Required designer variable.
		''' </summary>
		Private components As System.ComponentModel.Container = Nothing
        Private WithEvents cbShowRegionDemo As CheckBox
        Private WithEvents cbReflectY As System.Windows.Forms.CheckBox
        Private WithEvents cbReflectX As System.Windows.Forms.CheckBox
        Private _f2 As New Form2
        Public Sub New()

            InitializeComponent()
        End Sub

        ''' <summary>
        ''' Clean up any resources being used.
        ''' </summary>
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If components IsNot Nothing Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region "Windows Form Designer generated code"
        ''' <summary>
        ''' Required method for Designer support - do not modify
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
            Me.pictureBox1 = New System.Windows.Forms.PictureBox
            Me.button1 = New System.Windows.Forms.Button
            Me.tRotDeg = New System.Windows.Forms.TrackBar
            Me.lblRotDeg = New System.Windows.Forms.Label
            Me.listBox1 = New System.Windows.Forms.ListBox
            Me.buttonDown = New System.Windows.Forms.Button
            Me.buttonUp = New System.Windows.Forms.Button
            Me.label2 = New System.Windows.Forms.Label
            Me.cbRotate = New System.Windows.Forms.CheckBox
            Me.cbTranslation = New System.Windows.Forms.CheckBox
            Me.label3 = New System.Windows.Forms.Label
            Me.lblTransX = New System.Windows.Forms.Label
            Me.tTransX = New System.Windows.Forms.TrackBar
            Me.label5 = New System.Windows.Forms.Label
            Me.lblTransY = New System.Windows.Forms.Label
            Me.tTransY = New System.Windows.Forms.TrackBar
            Me.label9 = New System.Windows.Forms.Label
            Me.lblRotY = New System.Windows.Forms.Label
            Me.tRotY = New System.Windows.Forms.TrackBar
            Me.label11 = New System.Windows.Forms.Label
            Me.lblRotX = New System.Windows.Forms.Label
            Me.tRotX = New System.Windows.Forms.TrackBar
            Me.label14 = New System.Windows.Forms.Label
            Me.lblStrY = New System.Windows.Forms.Label
            Me.tStrY = New System.Windows.Forms.TrackBar
            Me.cbStretch = New System.Windows.Forms.CheckBox
            Me.label16 = New System.Windows.Forms.Label
            Me.lblStrX = New System.Windows.Forms.Label
            Me.tStrX = New System.Windows.Forms.TrackBar
            Me.pictureBoxBase = New System.Windows.Forms.PictureBox
            Me.cbFlipY = New System.Windows.Forms.CheckBox
            Me.btnReset = New System.Windows.Forms.Button
            Me.cbRealtime = New System.Windows.Forms.CheckBox
            Me.cbShowRegionDemo = New System.Windows.Forms.CheckBox
            Me.cbReflectY = New System.Windows.Forms.CheckBox
            Me.cbReflectX = New System.Windows.Forms.CheckBox
            CType(Me.pictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tRotDeg, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tTransX, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tTransY, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tRotY, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tRotX, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tStrY, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.tStrX, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.pictureBoxBase, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'pictureBox1
            '
            Me.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            Me.pictureBox1.Location = New System.Drawing.Point(8, 8)
            Me.pictureBox1.Name = "pictureBox1"
            Me.pictureBox1.Size = New System.Drawing.Size(400, 400)
            Me.pictureBox1.TabIndex = 0
            Me.pictureBox1.TabStop = False
            '
            'button1
            '
            Me.button1.Location = New System.Drawing.Point(344, 424)
            Me.button1.Name = "button1"
            Me.button1.Size = New System.Drawing.Size(64, 24)
            Me.button1.TabIndex = 1
            Me.button1.Text = "Go"
            '
            'tRotDeg
            '
            Me.tRotDeg.AutoSize = False
            Me.tRotDeg.LargeChange = 1
            Me.tRotDeg.Location = New System.Drawing.Point(496, 40)
            Me.tRotDeg.Maximum = 90
            Me.tRotDeg.Minimum = -90
            Me.tRotDeg.Name = "tRotDeg"
            Me.tRotDeg.Size = New System.Drawing.Size(104, 24)
            Me.tRotDeg.TabIndex = 2
            Me.tRotDeg.TickFrequency = 30
            '
            'lblRotDeg
            '
            Me.lblRotDeg.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblRotDeg.Location = New System.Drawing.Point(600, 40)
            Me.lblRotDeg.Name = "lblRotDeg"
            Me.lblRotDeg.Size = New System.Drawing.Size(32, 24)
            Me.lblRotDeg.TabIndex = 3
            '
            'listBox1
            '
            Me.listBox1.Location = New System.Drawing.Point(432, 352)
            Me.listBox1.Name = "listBox1"
            Me.listBox1.Size = New System.Drawing.Size(176, 56)
            Me.listBox1.TabIndex = 4
            '
            'buttonDown
            '
            Me.buttonDown.Location = New System.Drawing.Point(616, 382)
            Me.buttonDown.Name = "buttonDown"
            Me.buttonDown.Size = New System.Drawing.Size(16, 24)
            Me.buttonDown.TabIndex = 5
            Me.buttonDown.Text = "-"
            '
            'buttonUp
            '
            Me.buttonUp.Location = New System.Drawing.Point(616, 352)
            Me.buttonUp.Name = "buttonUp"
            Me.buttonUp.Size = New System.Drawing.Size(16, 24)
            Me.buttonUp.TabIndex = 6
            Me.buttonUp.Text = "+"
            '
            'label2
            '
            Me.label2.Location = New System.Drawing.Point(448, 40)
            Me.label2.Name = "label2"
            Me.label2.Size = New System.Drawing.Size(48, 24)
            Me.label2.TabIndex = 7
            Me.label2.Text = "Degree"
            '
            'cbRotate
            '
            Me.cbRotate.Location = New System.Drawing.Point(424, 8)
            Me.cbRotate.Name = "cbRotate"
            Me.cbRotate.Size = New System.Drawing.Size(80, 16)
            Me.cbRotate.TabIndex = 8
            Me.cbRotate.Text = "Rotation"
            '
            'cbTranslation
            '
            Me.cbTranslation.Location = New System.Drawing.Point(432, 144)
            Me.cbTranslation.Name = "cbTranslation"
            Me.cbTranslation.Size = New System.Drawing.Size(88, 16)
            Me.cbTranslation.TabIndex = 12
            Me.cbTranslation.Text = "Translation"
            '
            'label3
            '
            Me.label3.Location = New System.Drawing.Point(448, 176)
            Me.label3.Name = "label3"
            Me.label3.Size = New System.Drawing.Size(48, 24)
            Me.label3.TabIndex = 11
            Me.label3.Text = "X"
            '
            'lblTransX
            '
            Me.lblTransX.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblTransX.Location = New System.Drawing.Point(600, 176)
            Me.lblTransX.Name = "lblTransX"
            Me.lblTransX.Size = New System.Drawing.Size(32, 24)
            Me.lblTransX.TabIndex = 10
            '
            'tTransX
            '
            Me.tTransX.AutoSize = False
            Me.tTransX.LargeChange = 1
            Me.tTransX.Location = New System.Drawing.Point(496, 176)
            Me.tTransX.Maximum = 150
            Me.tTransX.Minimum = -150
            Me.tTransX.Name = "tTransX"
            Me.tTransX.Size = New System.Drawing.Size(104, 24)
            Me.tTransX.TabIndex = 9
            Me.tTransX.TickFrequency = 20
            '
            'label5
            '
            Me.label5.Location = New System.Drawing.Point(448, 208)
            Me.label5.Name = "label5"
            Me.label5.Size = New System.Drawing.Size(48, 24)
            Me.label5.TabIndex = 15
            Me.label5.Text = "Y"
            '
            'lblTransY
            '
            Me.lblTransY.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblTransY.Location = New System.Drawing.Point(600, 208)
            Me.lblTransY.Name = "lblTransY"
            Me.lblTransY.Size = New System.Drawing.Size(32, 24)
            Me.lblTransY.TabIndex = 14
            '
            'tTransY
            '
            Me.tTransY.AutoSize = False
            Me.tTransY.LargeChange = 1
            Me.tTransY.Location = New System.Drawing.Point(496, 208)
            Me.tTransY.Maximum = 150
            Me.tTransY.Minimum = -150
            Me.tTransY.Name = "tTransY"
            Me.tTransY.Size = New System.Drawing.Size(104, 24)
            Me.tTransY.TabIndex = 13
            Me.tTransY.TickFrequency = 20
            '
            'label9
            '
            Me.label9.Location = New System.Drawing.Point(448, 104)
            Me.label9.Name = "label9"
            Me.label9.Size = New System.Drawing.Size(48, 24)
            Me.label9.TabIndex = 23
            Me.label9.Text = "Y"
            '
            'lblRotY
            '
            Me.lblRotY.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblRotY.Location = New System.Drawing.Point(600, 104)
            Me.lblRotY.Name = "lblRotY"
            Me.lblRotY.Size = New System.Drawing.Size(32, 24)
            Me.lblRotY.TabIndex = 22
            '
            'tRotY
            '
            Me.tRotY.AutoSize = False
            Me.tRotY.LargeChange = 1
            Me.tRotY.Location = New System.Drawing.Point(496, 104)
            Me.tRotY.Maximum = 50
            Me.tRotY.Minimum = -50
            Me.tRotY.Name = "tRotY"
            Me.tRotY.Size = New System.Drawing.Size(104, 24)
            Me.tRotY.TabIndex = 21
            Me.tRotY.TickFrequency = 10
            '
            'label11
            '
            Me.label11.Location = New System.Drawing.Point(448, 72)
            Me.label11.Name = "label11"
            Me.label11.Size = New System.Drawing.Size(48, 24)
            Me.label11.TabIndex = 20
            Me.label11.Text = "X"
            '
            'lblRotX
            '
            Me.lblRotX.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblRotX.Location = New System.Drawing.Point(600, 72)
            Me.lblRotX.Name = "lblRotX"
            Me.lblRotX.Size = New System.Drawing.Size(32, 24)
            Me.lblRotX.TabIndex = 19
            '
            'tRotX
            '
            Me.tRotX.AutoSize = False
            Me.tRotX.LargeChange = 1
            Me.tRotX.Location = New System.Drawing.Point(496, 72)
            Me.tRotX.Maximum = 50
            Me.tRotX.Minimum = -50
            Me.tRotX.Name = "tRotX"
            Me.tRotX.Size = New System.Drawing.Size(104, 24)
            Me.tRotX.TabIndex = 18
            Me.tRotX.TickFrequency = 10
            '
            'label14
            '
            Me.label14.Location = New System.Drawing.Point(448, 312)
            Me.label14.Name = "label14"
            Me.label14.Size = New System.Drawing.Size(48, 24)
            Me.label14.TabIndex = 30
            Me.label14.Text = "Y"
            '
            'lblStrY
            '
            Me.lblStrY.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblStrY.Location = New System.Drawing.Point(600, 312)
            Me.lblStrY.Name = "lblStrY"
            Me.lblStrY.Size = New System.Drawing.Size(32, 24)
            Me.lblStrY.TabIndex = 29
            '
            'tStrY
            '
            Me.tStrY.AutoSize = False
            Me.tStrY.LargeChange = 1
            Me.tStrY.Location = New System.Drawing.Point(496, 312)
            Me.tStrY.Maximum = 20
            Me.tStrY.Minimum = 1
            Me.tStrY.Name = "tStrY"
            Me.tStrY.Size = New System.Drawing.Size(104, 24)
            Me.tStrY.TabIndex = 28
            Me.tStrY.Value = 10
            '
            'cbStretch
            '
            Me.cbStretch.Location = New System.Drawing.Point(432, 248)
            Me.cbStretch.Name = "cbStretch"
            Me.cbStretch.Size = New System.Drawing.Size(80, 16)
            Me.cbStretch.TabIndex = 27
            Me.cbStretch.Text = "Stretch"
            '
            'label16
            '
            Me.label16.Location = New System.Drawing.Point(448, 280)
            Me.label16.Name = "label16"
            Me.label16.Size = New System.Drawing.Size(48, 24)
            Me.label16.TabIndex = 26
            Me.label16.Text = "X"
            '
            'lblStrX
            '
            Me.lblStrX.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
            Me.lblStrX.Location = New System.Drawing.Point(600, 280)
            Me.lblStrX.Name = "lblStrX"
            Me.lblStrX.Size = New System.Drawing.Size(32, 24)
            Me.lblStrX.TabIndex = 25
            '
            'tStrX
            '
            Me.tStrX.AutoSize = False
            Me.tStrX.LargeChange = 1
            Me.tStrX.Location = New System.Drawing.Point(496, 280)
            Me.tStrX.Maximum = 20
            Me.tStrX.Minimum = 1
            Me.tStrX.Name = "tStrX"
            Me.tStrX.Size = New System.Drawing.Size(104, 24)
            Me.tStrX.TabIndex = 24
            Me.tStrX.Value = 10
            '
            'pictureBoxBase
            '
            Me.pictureBoxBase.Image = CType(resources.GetObject("pictureBoxBase.Image"), System.Drawing.Image)
            Me.pictureBoxBase.Location = New System.Drawing.Point(56, 448)
            Me.pictureBoxBase.Name = "pictureBoxBase"
            Me.pictureBoxBase.Size = New System.Drawing.Size(100, 100)
            Me.pictureBoxBase.TabIndex = 32
            Me.pictureBoxBase.TabStop = False
            Me.pictureBoxBase.Visible = False
            '
            'cbFlipY
            '
            Me.cbFlipY.Checked = True
            Me.cbFlipY.CheckState = System.Windows.Forms.CheckState.Checked
            Me.cbFlipY.Location = New System.Drawing.Point(16, 424)
            Me.cbFlipY.Name = "cbFlipY"
            Me.cbFlipY.Size = New System.Drawing.Size(112, 16)
            Me.cbFlipY.TabIndex = 33
            Me.cbFlipY.Text = "Flip Y Coordinates"
            '
            'btnReset
            '
            Me.btnReset.Location = New System.Drawing.Point(264, 424)
            Me.btnReset.Name = "btnReset"
            Me.btnReset.Size = New System.Drawing.Size(64, 24)
            Me.btnReset.TabIndex = 34
            Me.btnReset.Text = "Reset"
            '
            'cbRealtime
            '
            Me.cbRealtime.Checked = True
            Me.cbRealtime.CheckState = System.Windows.Forms.CheckState.Checked
            Me.cbRealtime.Location = New System.Drawing.Point(144, 424)
            Me.cbRealtime.Name = "cbRealtime"
            Me.cbRealtime.Size = New System.Drawing.Size(112, 16)
            Me.cbRealtime.TabIndex = 35
            Me.cbRealtime.Text = "Real Time"
            '
            'cbShowRegionDemo
            '
            Me.cbShowRegionDemo.AutoSize = True
            Me.cbShowRegionDemo.CheckAlign = System.Drawing.ContentAlignment.MiddleRight
            Me.cbShowRegionDemo.Location = New System.Drawing.Point(541, 424)
            Me.cbShowRegionDemo.Name = "cbShowRegionDemo"
            Me.cbShowRegionDemo.Size = New System.Drawing.Size(91, 17)
            Me.cbShowRegionDemo.TabIndex = 36
            Me.cbShowRegionDemo.Text = "Region Demo"
            Me.cbShowRegionDemo.UseVisualStyleBackColor = True
            '
            'cbReflectY
            '
            Me.cbReflectY.Location = New System.Drawing.Point(687, 35)
            Me.cbReflectY.Name = "cbReflectY"
            Me.cbReflectY.Size = New System.Drawing.Size(130, 25)
            Me.cbReflectY.TabIndex = 40
            Me.cbReflectY.Text = "Reflect Along Y axis"
            '
            'cbReflectX
            '
            Me.cbReflectX.Location = New System.Drawing.Point(687, 1)
            Me.cbReflectX.Name = "cbReflectX"
            Me.cbReflectX.Size = New System.Drawing.Size(130, 30)
            Me.cbReflectX.TabIndex = 39
            Me.cbReflectX.Text = "Refect Along X axis"
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(893, 466)
            Me.Controls.Add(Me.cbReflectY)
            Me.Controls.Add(Me.cbReflectX)
            Me.Controls.Add(Me.cbShowRegionDemo)
            Me.Controls.Add(Me.cbRealtime)
            Me.Controls.Add(Me.btnReset)
            Me.Controls.Add(Me.cbFlipY)
            Me.Controls.Add(Me.pictureBoxBase)
            Me.Controls.Add(Me.label14)
            Me.Controls.Add(Me.lblStrY)
            Me.Controls.Add(Me.tStrY)
            Me.Controls.Add(Me.cbStretch)
            Me.Controls.Add(Me.label16)
            Me.Controls.Add(Me.lblStrX)
            Me.Controls.Add(Me.tStrX)
            Me.Controls.Add(Me.label9)
            Me.Controls.Add(Me.lblRotY)
            Me.Controls.Add(Me.tRotY)
            Me.Controls.Add(Me.label11)
            Me.Controls.Add(Me.lblRotX)
            Me.Controls.Add(Me.tRotX)
            Me.Controls.Add(Me.label5)
            Me.Controls.Add(Me.lblTransY)
            Me.Controls.Add(Me.tTransY)
            Me.Controls.Add(Me.cbTranslation)
            Me.Controls.Add(Me.label3)
            Me.Controls.Add(Me.lblTransX)
            Me.Controls.Add(Me.tTransX)
            Me.Controls.Add(Me.cbRotate)
            Me.Controls.Add(Me.label2)
            Me.Controls.Add(Me.buttonUp)
            Me.Controls.Add(Me.buttonDown)
            Me.Controls.Add(Me.listBox1)
            Me.Controls.Add(Me.lblRotDeg)
            Me.Controls.Add(Me.tRotDeg)
            Me.Controls.Add(Me.button1)
            Me.Controls.Add(Me.pictureBox1)
            Me.Name = "Form1"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "Transformation Tester"
            CType(Me.pictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tRotDeg, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tTransX, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tTransY, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tRotY, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tRotX, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tStrY, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.tStrX, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.pictureBoxBase, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub
#End Region

        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        <STAThread()> _
        Private Shared Sub Main()
            Application.Run(New Form1())
        End Sub



        Private Sub DrawAxes(ByVal g As Graphics, ByVal flipY As Boolean)

            'Hold the old transform of g
            Dim mm As Matrix = g.Transform

            'Clear the transform of g
            g.Transform = New Matrix()
            'Create a red pen
            Dim p As New Pen(Brushes.Red, 1)

            Dim m As New Matrix()

            'move the origin to 200,200
            m.Translate(200, 200)
            'apply the transformation
            g.Transform = m

            'draw the axes
            g.DrawLine(p, -200, 0, 200, 0)
            'horizontal
            g.DrawLine(p, 0, -200, 0, 200)
            'vetical	

            For i As Integer = -150 To 150 Step 50
                'calibrate the vertical axis with horizontal text
                If flipY Then
                    g.DrawString(i.ToString(), Me.Font, Brushes.Red, 5, -i)
                Else
                    g.DrawString(i.ToString(), Me.Font, Brushes.Red, 5, i)
                End If

                'tick the vertical axis with horizontal ticks
                g.DrawLine(p, -5, i, 5, i)
                'tick the horizontal axis with vertical ticks

                g.DrawLine(p, i, -5, i, 5)
            Next

            'prepend the 90 deg clockwise rotation
            'so now m would be a matix for a 90 deg clockwise rotation 
            'followed by translation by 200,200
            m.Rotate(90, MatrixOrder.Prepend)

            'override with the new transformation
            g.Transform = m

            For i As Integer = -150 To 150 Step 50
                'calibrate the horizontal axis with vertical text
                '|
                '|
                '|100
                '|
                '|
                'after the rotation would be
                '
                '_____________
                '    _
                '    O
                '    O
                '
                g.DrawString(i.ToString(), Me.Font, Brushes.Red, 5, -i)
            Next

            'Restore the old transform of g
            g.Transform = mm

        End Sub

        Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

            'allocate image for persistence
            Dim img As Image = New Bitmap(400, 400)

            'for region demo
            _f2.BackgroundImage = New Bitmap(400, 400)

            'assigned to pictureBox 1
            pictureBox1.Image = img
            Dim g As Graphics = Graphics.FromImage(pictureBox1.Image)

            'for region demo
            Dim g1 As Graphics = Graphics.FromImage(_f2.BackgroundImage)


            'Draw the graphical axes
            DrawAxes(g, (cbFlipY.CheckState = CheckState.Checked))

            'Create a new metrix
            Dim mm As New Matrix()

            'Flip Y axis
            If cbFlipY.CheckState = CheckState.Checked Then
                mm = New Matrix(1, 0, 0, -1, 0, 0)
            End If
            'Bring Center to 200,200
            mm.Translate(200, 200, MatrixOrder.Append)
            'Apply world transformation on picture box 
            g.Transform = mm
            g1.Transform = mm

            'Create a new matrix for custom transformations
            Dim mm1 As New Matrix()

            'append the transformation as ordered by the lsitbox
            For i As Integer = 0 To listBox1.Items.Count - 1
                'somehow when the y axis is flip
                'the direction of the rotation also changed
                'thus when the y axis is flip, we
                'multiply the angle by a -1


                If listBox1.Items(i).ToString() = "ReflectX" Then
                    Dim mreflex = New Matrix(1, 0, 0, -1, 0, 0)
                    mm1.Multiply(mreflex, MatrixOrder.Append)
                End If

                If listBox1.Items(i).ToString() = "ReflectY" Then
                    Dim mreflex = New Matrix(-1, 0, 0, 1, 0, 0)
                    mm1.Multiply(mreflex, MatrixOrder.Append)
                End If

                If listBox1.Items(i).ToString() = "Rotate" Then
                    mm1.RotateAt((If(cbFlipY.CheckState = CheckState.Checked, -1, 1)) * Integer.Parse(lblRotDeg.Text), New Point(Integer.Parse(lblRotX.Text), Integer.Parse(lblRotY.Text)), MatrixOrder.Append)
                End If


                If listBox1.Items(i).ToString() = "Translation" Then
                    mm1.Translate(Integer.Parse(lblTransX.Text), Integer.Parse(lblTransY.Text), MatrixOrder.Append)
                End If

                If listBox1.Items(i).ToString() = "Stretch" Then
                    mm1.Scale(Single.Parse(lblStrX.Text), Single.Parse(lblStrY.Text), MatrixOrder.Append)

                End If
            Next


            Dim gp As New GraphicsPath()


            Dim imgpic As Image = DirectCast(pictureBoxBase.Image.Clone(), Image)
            Dim imgpic1 As Image = DirectCast(pictureBoxBase.Image.Clone(), Image)
            Graphics.FromImage(imgpic1).DrawRectangle(New Pen(Color.Red, 3), 0, 0, imgpic1.Width - 1, imgpic1.Height - 1)

            'the coordinate of the source parralleogram must be
            'point 1 = left top corner
            'point 2 = right top corner
            'point 3 = right bottom corner
            Dim psrc As PointF()

            If cbFlipY.CheckState = CheckState.Checked Then
                psrc = New PointF() {New Point(0, imgpic.Height), New Point(imgpic.Width, imgpic.Height), New Point(0, 0)}
            Else
                psrc = New PointF() {New Point(0, 0), New Point(imgpic.Width, 0), New Point(0, imgpic.Height)}
            End If

            gp.AddPolygon(psrc)

            'apply the transformation matrix on the graphical path
            gp.Transform(mm1)
            'get the resulting path points
            Dim pts As PointF() = gp.PathPoints


            'draw on the picturebox content of imgpic using the local transformation 
            'using the resulting parralleogram described by pts
            g.DrawImage(imgpic, pts)

            'region demo
            'similarly draw pasiing in the same parralleogram, but we use the source image imgpic1 that has a red border drawn
            g1.DrawImage(imgpic1, pts)

            pictureBox1.Refresh()


            'for region demo
            Dim gp1 As New GraphicsPath()
            'we are using psrc1 to describe a polygon, so the points must be in clockwise/antoclockwise order
            Dim psrc1 As PointF() = New PointF() {New Point(0, 0), New Point(imgpic.Width, 0), New Point(imgpic.Width, imgpic.Height), New Point(0, imgpic.Height)}
            gp1.AddPolygon(psrc1)

            'this is like doing all the transformation mm1 and then lastly do the mm ops
            mm1.Multiply(mm, MatrixOrder.Append)

            'region demo
            gp1.Transform(mm1)
            _f2.Region = New Region(gp1)
            If _f2.Visible Then
                _f2.Refresh()
            End If

        End Sub

        Private Sub tRotDeg_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tRotDeg.ValueChanged
            lblRotDeg.Text = tRotDeg.Value.ToString()
            cbRotate.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'region demo
            '_f2 = New Form2()
            _f2.TopMost = True
            cbShowRegionDemo_CheckedChanged(Nothing, Nothing)

            tRotDeg.Value = 0
            tRotX.Value = 0
            tRotY.Value = 0

            lblRotDeg.Text = tRotDeg.Value.ToString()
            lblRotX.Text = tRotX.Value.ToString()
            lblRotY.Text = tRotY.Value.ToString()

            tTransX.Value = 0
            tTransY.Value = 0

            lblTransX.Text = tTransX.Value.ToString()
            lblTransY.Text = tTransY.Value.ToString()

            tStrX.Value = 10
            tStrY.Value = 10

            lblStrX.Text = [String].Format("{0:0.0}", (tStrX.Value / 10.0))
            lblStrY.Text = [String].Format("{0:0.0}", (tStrY.Value / 10.0))

            cbFlipY.CheckState = CheckState.Checked
            cbRotate.CheckState = CheckState.Unchecked
            cbTranslation.CheckState = CheckState.Unchecked
            cbStretch.CheckState = CheckState.Unchecked

            button1_Click(Me, Nothing)

        End Sub

        Private Sub buttonDown_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonDown.Click
            Dim index As Integer = listBox1.SelectedIndex
            If index >= listBox1.Items.Count - 1 Then
                Return
            End If
            If (index) <= -1 Then
                Return
            End If
            Dim s As String = DirectCast(listBox1.Items(index), String)
            listBox1.Items.RemoveAt(index)
            listBox1.Items.Insert(index + 1, s)
            listBox1.SelectedIndex = index + 1
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub buttonUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonUp.Click
            Dim index As Integer = listBox1.SelectedIndex
            If (index) <= 0 Then
                Return
            End If
            Dim s As String = DirectCast(listBox1.Items(index), String)
            listBox1.Items.RemoveAt(index)
            listBox1.Items.Insert(index - 1, s)
            listBox1.SelectedIndex = index - 1
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If

        End Sub

        Private Sub UpdateListBox(ByVal cb As CheckBox, ByVal s As [String])
            If cb.CheckState = CheckState.Checked Then
                Dim found As Boolean = False
                For i As Integer = 0 To listBox1.Items.Count - 1
                    If listBox1.Items(i).ToString() = s Then
                        found = True
                        Exit For
                    End If
                Next

                If Not found Then
                    listBox1.Items.Add(s)
                    listBox1.SelectedIndex = listBox1.Items.Count - 1

                End If
            Else
                For i As Integer = 0 To listBox1.Items.Count - 1
                    If listBox1.Items(i).ToString() = s Then
                        listBox1.Items.RemoveAt(i)

                        If i > 0 Then
                            listBox1.SelectedIndex = i - 1
                        End If
                        If i = 0 Then
                            If listBox1.Items.Count >= 1 Then
                                listBox1.SelectedIndex = 0
                            End If
                        End If

                        Exit For
                    End If
                Next
            End If
        End Sub

        Private Sub cbRotate_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbRotate.CheckedChanged
            UpdateListBox(DirectCast(sender, CheckBox), "Rotate")
        End Sub

        Private Sub cbTranslation_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbTranslation.CheckedChanged
            UpdateListBox(DirectCast(sender, CheckBox), "Translation")
        End Sub

        Private Sub cbStretch_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbStretch.CheckedChanged
            UpdateListBox(DirectCast(sender, CheckBox), "Stretch")
        End Sub

        Private Sub tRotX_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tRotX.ValueChanged
            lblRotX.Text = tRotX.Value.ToString()
            cbRotate.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub tRotY_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tRotY.ValueChanged
            lblRotY.Text = tRotY.Value.ToString()
            cbRotate.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub tTransX_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTransX.ValueChanged
            lblTransX.Text = tTransX.Value.ToString()
            cbTranslation.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub tTransY_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTransY.ValueChanged
            lblTransY.Text = tTransY.Value.ToString()
            cbTranslation.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub tStrX_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tStrX.ValueChanged
            lblStrX.Text = [String].Format("{0:0.0}", (tStrX.Value / 10.0))
            cbStretch.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub tStrY_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tStrY.ValueChanged
            lblStrY.Text = [String].Format("{0:0.0}", (tStrY.Value / 10.0))
            cbStretch.CheckState = CheckState.Checked
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub cbFlipY_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbFlipY.CheckedChanged
            button1_Click(sender, Nothing)
        End Sub

        Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
            _f2.Close()
            Form1_Load(sender, Nothing)

        End Sub

        Private Sub cbShowRegionDemo_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbShowRegionDemo.CheckedChanged
            Try
                _f2.Visible = cbShowRegionDemo.Checked
                Dim rt As Rectangle = Me.RectangleToScreen(New Rectangle(pictureBox1.Left, pictureBox1.Top, pictureBox1.Width, pictureBox1.Height))

                _f2.Top = rt.Top
                _f2.Left = rt.Left - 400
            Catch
            End Try
        End Sub

        Private Sub Form1_LocationChanged(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.LocationChanged
            cbShowRegionDemo_CheckedChanged(Nothing, Nothing)
        End Sub


        Private Sub cbReflectX_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbReflectX.CheckedChanged
            UpdateListBox(DirectCast(sender, CheckBox), "ReflectX")
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub

        Private Sub cbReflectY_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbReflectY.CheckedChanged
            UpdateListBox(DirectCast(sender, CheckBox), "ReflectY")
            If cbRealtime.CheckState = CheckState.Checked Then
                button1_Click(sender, Nothing)
            End If
        End Sub
    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Yang Kok Wah
Software Developer (Senior)
Singapore Singapore
Yang Kok Wah is a Software Specialist in a leading System/Solution Integration Company in Singapore. He has more than 20 years experience in software development, specializing in areas of Biometrics, Smartcards and Image Processing. He has worked with VB, C#, Java and C/C++. He graduated from University of London with BSc(Hons) in Computing and also holds a Business Administration degree from National University of Singapore.

He likes Graphics, Games, AI and Image Processing.

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180820.1 | Last Updated 1 Jul 2016
Article Copyright 2004 by Yang Kok Wah
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid