Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

SetLine In DotNet

Solved!
Go to solution

Hi Everybody,

I develop an application using VB.NET and VISION.
I want to do a SetLine to change some pixels of my Image. Unfortunately  i have the exception 
"You have passed an invalid type into a parameter of a VARIANT type"

Here is an example of code:

 

Dim Image As New NationalInstruments.CWIMAQControls.CWIMAQImage

Dim line As New NationalInstruments.CWIMAQControls.CWIMAQImage

Dim data(,) As Byte

Dim ligne As New NationalInstruments.CWIMAQControls.CWIMAQLine

 

Image.Type = NationalInstruments.CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeU8

line.Type = NationalInstruments.CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeU8

line.SetSize(1, 100)

Image.SetSize(100, 100)

ReDim data(1, 100)

 

data = line.ImageToArray()

ligne.Initialize(1, 1, 1, 100)

 

AxCWIMAQVision1.SetPixel2(line, New NationalInstruments.CWIMAQControls.CWIMAQPoint, 1)  // Ok with this function

AxCWIMAQVision1.SetLine2(image, ligne, data) // Exception Thrown here

 

I understand well that AxCWimaqVision is an active X control and NI supplied a wrapper code of the C++ VISION DLL for DotNet. So we have to pass VARIANT type.
But in dotnet the Variant Type is the object type. In My code SetPixel accepts an integer and the DLL cast for the appropriate type to do the function...
In SetLine i have tried an array of byte , an object ... It doesn't work strange...

In LV and CVI there is no problem. In CVI we pass a char* to the data type

 

Thanks a lot!!

0 Kudos
Message 1 of 3
(4,020 Views)

Hi kikou,

 

You're using the ImagetoArray function, which creates a 2D array.  The array is just an array with one column, so it seems like a 1D array.  You will need to bring this down to a 1D array to use it in the SetLine2 function.

Stephen Meserve
National Instruments
0 Kudos
Message 2 of 3
(3,987 Views)
Solution
Accepted by topic author kikou
Hi
You are right... I have a linescan camera delivering one line of 12288 pixels i didn't see that the image is still a 2D array
But the best way to do that is to use GetLine and then SetLine...
An other function is more optimized, is ImageToImage. With this function it is not necessary to convert image to arrays!!

Thanks
0 Kudos
Message 3 of 3
(3,967 Views)