Imports System.io

Public Class Form1

    Private eng As CaoEngine
    Private ctrl As CaoController
    Private file1 As CaoFile
    Private file2 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")
        file1 = ctrl.AddFile("image1", "ID=1")
        file2 = ctrl.AddFile("image2", "ID=11")

    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(file1)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(file2)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' ID=1の画像データをID=11に保存
        file2.Value = file1.Value

        Dim bArray() As Byte
        Dim mstreamCur As MemoryStream

        ' ID=1の画像表示
        bArray = file1.Value
        mstreamCur = New MemoryStream(bArray)
        PictureBox1.Image = Image.FromStream(mstreamCur)

        ' ID=11の画像表示
        bArray = file2.Value
        mstreamCur = New MemoryStream(bArray)
        PictureBox2.Image = Image.FromStream(mstreamCur)

    End Sub

End Class
