Option Strict Off
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'For the start-up form, the first instance created is the default instance.
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'This call is required by the Windows Form Designer.
		InitializeComponent()
	End Sub
	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
		If Disposing Then
			If Not components Is Nothing Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(Disposing)
	End Sub
	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer
    Public WithEvents Command4 As System.Windows.Forms.Button
	Public WithEvents Command3 As System.Windows.Forms.Button
	Public WithEvents Command2 As System.Windows.Forms.Button
	Public WithEvents Command1 As System.Windows.Forms.Button
	Public WithEvents ImageKit1 As AxIMAGEKIT7Lib.AxImageKit
	Public WithEvents Text1 As System.Windows.Forms.TextBox
	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Command4 = New System.Windows.Forms.Button
        Me.Command3 = New System.Windows.Forms.Button
        Me.Command2 = New System.Windows.Forms.Button
        Me.Command1 = New System.Windows.Forms.Button
        Me.ImageKit1 = New AxIMAGEKIT7Lib.AxImageKit
        Me.Text1 = New System.Windows.Forms.TextBox
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Command4
        '
        Me.Command4.BackColor = System.Drawing.SystemColors.Control
        Me.Command4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command4.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command4.Location = New System.Drawing.Point(520, 248)
        Me.Command4.Name = "Command4"
        Me.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command4.Size = New System.Drawing.Size(113, 33)
        Me.Command4.TabIndex = 5
        Me.Command4.Text = "Redisplay Original"
        '
        'Command3
        '
        Me.Command3.BackColor = System.Drawing.SystemColors.Control
        Me.Command3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command3.Location = New System.Drawing.Point(520, 144)
        Me.Command3.Name = "Command3"
        Me.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command3.Size = New System.Drawing.Size(113, 33)
        Me.Command3.TabIndex = 4
        Me.Command3.Text = "Select and Display"
        '
        'Command2
        '
        Me.Command2.BackColor = System.Drawing.SystemColors.Control
        Me.Command2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command2.Location = New System.Drawing.Point(520, 408)
        Me.Command2.Name = "Command2"
        Me.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command2.Size = New System.Drawing.Size(113, 33)
        Me.Command2.TabIndex = 3
        Me.Command2.Text = "End"
        '
        'Command1
        '
        Me.Command1.BackColor = System.Drawing.SystemColors.Control
        Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command1.Location = New System.Drawing.Point(520, 72)
        Me.Command1.Name = "Command1"
        Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command1.Size = New System.Drawing.Size(113, 33)
        Me.Command1.TabIndex = 2
        Me.Command1.Text = "Load Image"
        '
        'ImageKit1
        '
        Me.ImageKit1.Location = New System.Drawing.Point(8, 72)
        Me.ImageKit1.Name = "ImageKit1"
        Me.ImageKit1.OcxState = CType(resources.GetObject("ImageKit1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.ImageKit1.Size = New System.Drawing.Size(505, 400)
        Me.ImageKit1.TabIndex = 1
        '
        'Text1
        '
        Me.Text1.AcceptsReturn = True
        Me.Text1.AutoSize = False
        Me.Text1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
        Me.Text1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Text1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Text1.ForeColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(64, Byte), CType(0, Byte))
        Me.Text1.Location = New System.Drawing.Point(8, 0)
        Me.Text1.MaxLength = 0
        Me.Text1.Multiline = True
        Me.Text1.Name = "Text1"
        Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text1.Size = New System.Drawing.Size(625, 64)
        Me.Text1.TabIndex = 0
        Me.Text1.Text = "The SelectImage method allows you to copy a specific area on an image and is the " & _
        "first step in ""regional"" image processing. This sample gets you started using th" & _
        "e SelectImage method. Because the RectDraw property is set to True, you can use " & _
        "your mouse to select a rectangle on the image. These coordinates are passed to t" & _
        "he SelectImage method and that area is copied and displayed. The original image " & _
        "handle is stored in a variable so that the original image can be redisplayed."
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(640, 486)
        Me.Controls.Add(Me.Command4)
        Me.Controls.Add(Me.Command3)
        Me.Controls.Add(Me.Command2)
        Me.Controls.Add(Me.Command1)
        Me.Controls.Add(Me.ImageKit1)
        Me.Controls.Add(Me.Text1)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Location = New System.Drawing.Point(4, 30)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text = "SelectImage Method"
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "Upgrade Support "
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
	Dim x(3) As Integer
	Dim y(3) As Integer
	Dim OriginalImageHandle As Integer
	
	Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
		
		'Free the image data that is referred to by the
		'OriginalImageHandle variable. This must be done manually
		If OriginalImageHandle <> 0 Then
			ImageKit1.FreeMemory(OriginalImageHandle)
			OriginalImageHandle = 0
		End If
		
		'display the Open file dialog and choose the image to be loaded...
		If ImageKit1.File.OpenFileDialog = False Then
			Exit Sub
		End If
		
		'load the image file...
		ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad)
		
		'check to see that the loaded image is a raster image...
		If ImageKit1.ImageKind <> IMAGEKIT7Lib.ImageKindConstants.ikRasterImage Then
			ImageKit1.FreeMemory(ImageKit1.ImageHandle)
			MsgBox("Please load a raster image")
			Exit Sub
		End If
		
		'display the image in actual size mode...
		ImageKit1.ScrollBar = True
		ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikActualSize)
		
		'store the original image data so it is not overwritten...
		OriginalImageHandle = ImageKit1.CopyImage(ImageKit1.ImageHandle)
	End Sub
	
	Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
		Me.Close()
	End Sub
	
	Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
		Dim ret As Boolean
		
		'check to make sure an area has been selected with the mouse...
		If ImageKit1.RectRight = 0 Then
			MsgBox("Please use your mouse to select an area on the image.")
			Exit Sub
		End If
		
		'set the select mode...
		ImageKit1.Effect.SelectMode = IMAGEKIT7Lib.AreaSelectModeConstants.ikEffectPolygon
		
		'pass the selected area into the x and y coordinate arrays...
		x(0) = ImageKit1.RectLeft : y(0) = ImageKit1.RectTop
		x(1) = ImageKit1.RectRight : y(1) = ImageKit1.RectTop
		x(2) = ImageKit1.RectRight : y(2) = ImageKit1.RectBottom
		x(3) = ImageKit1.RectLeft : y(3) = ImageKit1.RectBottom
		
		'execute the SelectImage method...
		ret = ImageKit1.Effect.SelectImage(x(0), y(0), 4, 128, 128, 128)
		
		'reset mouse coordinates...
		ImageKit1.RectLeft = 0
		ImageKit1.RectTop = 0
		ImageKit1.RectRight = 0
		ImageKit1.RectBottom = 0
		
		ImageKit1.CtlRefresh()
		
	End Sub
	
	Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
		'redisplay the original image data...
		ImageKit1.ImageHandle = OriginalImageHandle
		ImageKit1.CtlRefresh()
		
		'store the original image data again so it is not overwritten...
		OriginalImageHandle = ImageKit1.CopyImage(ImageKit1.ImageHandle)
		
	End Sub
	
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		'allow the mouse to be used to select an area on the image...
		ImageKit1.RectDraw = True
	End Sub
End Class