Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

ReadFile in C# or Open with Bitmap object

Hello,

I use Visual Studio 2005 in C#. My project is a library.

First

I'm a problem with the last param of ReadFile(CWIMAQIMAGE, Path, object ColorPalette)

in the docs, the last params is optional, but not in C#!!!

I have teste to put in to null, but I have a exception.

Second

I would like open my picture from a Bitmap object, but I'm not find any function to do this.

This is my class:

class NIVision
{
    private CWIMAQImages image;

    public NIVision(String path)
    {
       ReadFile(image, path, null);
    }

    public NIVision(Bitmap bmp)
    {
       // I would like put bmp to image
    }

   public Bitmap getResult()
   {
       // I don't know to do this
       return image;
   }
}

Can you help me to resolve these problems.

Thanks
0 Kudos
Message 1 of 5
(6,327 Views)
I'm rewrite the library in VB.NET, but I'm the same error:

Nobody can help me?


Message Edité par lachinaj le 04-28-2008 06:51 AM
0 Kudos
Message 2 of 5
(6,297 Views)
lachinaj -

Sorry for the delayed response.

In C#, to pass a missing parameter to a function you have to use System.Type.Missing, not null.  So something like

axCWIMAQVision1.ReadFile(axCWIMAQViewer1.Image, @"c:\someimage.png", System.Type.Missing);

should work.

Unfortunately, there does not seem to be a direct way to load a bitmap into a CWIMAQImage.  You could copy the bitmap to the clipboard and use the CWIMAQVision.ReadImageFromClipboard() method to load it in an image, though.


Greg Stoll
Vision R&D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 3 of 5
(6,283 Views)
I don't understand my error, if y use the AxCWIMAQVision and Viewer and if this object is focused all is ok.
But if its not focused I am this error:
Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.

This is what I want, it's possible to do?

NationalInstruments.CWIMAQControls.CWIMAQVision vision = new NationalInstruments.CWIMAQControls.CWIMAQVision();
NationalInstruments.CWIMAQControls.CWIMAQImage image = new NationalInstruments.CWIMAQControls.CWIMAQImage();
int ret = vision.ReadImage(Image, "source.jpg", System.Type.Missing);
vision.Threshold(Image, Image, 0, 255, false, 90);
vision.WriteImage(Image, "image.jpg", NationalInstruments.CWIMAQControls.CWIMAQFileFormats.cwimaqFileJPEG, System.Type.Missing);
0 Kudos
Message 4 of 5
(6,273 Views)
Nobody can help me?

0 Kudos
Message 5 of 5
(6,210 Views)