
Public Class Form1

    Private eng As CaoEngine
    Private ctrl As CaoController
    Private file As CaoFile

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' オブジェクトの生成
        eng = New CaoEngine
        ctrl = eng.Workspaces.Item(0).AddController("sample", "CaoProv.OpenCV")
        file = ctrl.AddFile("image", "ID=1")
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        ' オブジェクトの解放
        System.Runtime.InteropServices.Marshal.ReleaseComObject(eng)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(ctrl)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(file)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ParaArr() As Object
        Dim bArray() As Byte

        ' 画像データの切り取り
        ParaArr = New Object(4) {0, 0, 0, 100, 100}
        bArray = file.Execute("Cut", ParaArr)

        ' 切り取り画像の表示
        Dim mstreamCur As New MemoryStream(bArray)
        PictureBox1.Image = Image.FromStream(mstreamCur)
    End Sub
End Class
