This example (demoPrograms\engine\VC#\call or demoPrograms\engine\VB\call) shows how to use the witCall function to call a WIC as if it were a function that returns a value.
In this example, the initialization and cleanup are standard. When you click Run!, the event handler function is called. In this function, there is a loop that is executed 3 times. Each time through the loop a different parameter value is passed to the WIC, and the WIC returns a different result to the user application.
The Call method is used to execute a WIC like a function. To use this method, the user needs to construct and release WiT data objects. This method is only available in WiT Engine for .Net namespace from version 2.0.
[C#]
string param = string.Format("{0}", (i + 1) * 10);
WiT.engine.SetOpParam(exehandle, "width", param);
WiT.engine.SetOpParam(exehandle, "height", param);
WiT.Object[] objs = new WiT.Object[2];
string[] names = { "image", "mean" };
objs[0] = new WiT.Object();
objs[1] = new WiT.Object();
WiT.engine.Call(exehandle, 2, names, objs);
WiT.Image img = objs[0].Image;
richTextBox1.Text +=
string.Format("Mean pixel value is: {0}\r\n", objs[1].Float);
int xpos = 100, ypos = 100;
int pixelPos = xpos * img.Width + ypos;
richTextBox1.Text +=
string.Format("Pixel at (100, 100) is {0}\r\n\r\n",
Marshal.ReadByte(img.Data, pixelPos));
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.ScrollToCaret();
objs[0].Release();
objs[1].Release();
[Visual Basic]
Dim param As String
Dim objs As WiT.Object()
objs = New WiT.Object() {Nothing, Nothing}
Dim names As String()
names = New String() {"image", "mean"}
...
param = String.Format("{0}", (i + 1) * 10)
WiT.engine.SetOpParam(exehandle, "width", param)
WiT.engine.SetOpParam(exehandle, "height", param)
objs(0) = New WiT.Object()
objs(1) = New WiT.Object()
WiT.engine.Call(exehandle, 2, names, objs)
Dim img As WiT.Image = objs(0).Image
richTextBox1.Text += String.Format("Mean pixel value is: {0}", objs(1).Float)
richTextBox1.Text += vbNewLine
Dim xpos As Integer = 100
Dim ypos As Integer = 100
Dim pixelPos As Integer = xpos * img.Width + ypos
richTextBox1.Text += String.Format("Pixel at (100, 100) is {0}", _
Marshal.ReadByte(img.Data, pixelPos))
richTextBox1.Text += vbNewLine
richTextBox1.SelectionStart = richTextBox1.Text.Length
richTextBox1.ScrollToCaret()
objs(0).Release()
objs(1).Release()
|