From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-29-2021 05:24 AM
I have IP camera over NVR which support RTSP.
learned from VLC scripting in LabVIEW by GriffinRU , view live steaming video under .NET picture box was success fully. However, can't figure out how to grab the image into LabVIEW (e.g. JPEG, PNG or IMAQ image).
I tried following the instruction from Convert a .NET PictureBox to an IMAQ Image but always fail with error (1172) :
Error 1172 occurred at Invoke Node Error calling method System.Drawing.Image.Save, (System.ArgumentNullException: Key cannot be null. Parameter name: key)
Possible reason(s):
LabVIEW: (Hex 0x494) A .NET exception occurred in an external assembly. For information about correcting this error, copy the following exception (in bold), and search the Microsoft Developer Network (MSDN) Web site or the Web for a possible explanation.
System.ArgumentNullException in PicBox to PNGstring (SubVI).vi->VLC - Play Stream&Snapshot&speed.vi
when I put probes, I found that the refnum of the image is 0 (zero = not a refnum), while the refnum of the picture box is present (not-zero). though I'm not sure if this is the cause or not.
any better Idea?
01-29-2021 05:30 AM
01-29-2021 05:45 AM - edited 01-29-2021 05:49 AM
Check out this post for some example code that may solve your issue:
https://forums.ni.com/t5/LabVIEW/NET-picturebox-convert-to-LabView-image/m-p/3125944#M897890
Edit:
Specifically, check out Get Image Data From PictureBox.vi
01-29-2021 05:58 AM
Suggestion: you also need to be much more careful to close EVERY reference you open. Some objects are IDisposable objects, and must be Disposed later (by using the Dispose method, not just by calling Close Reference). A thing like Color is a struct, not a disposable object, so it does not need to be Disposed; however, its LabVIEW refnum must be closed (using Close Reference).
You may not notice the leaks in a small program, but if you ever call this function in a loop you will eventually reach LabVIEW's internal refnum limit and crash the program with an Out of Memory error.
When in doubt, close it out!
01-29-2021 07:47 AM
I get exactly the same issue with this Guy's post:
01-29-2021 08:38 AM - edited 01-29-2021 08:39 AM
Posting a picture of someone else's code makes it difficult to debug your code.
The Image refnum should not be confused with the PictureBox refnum. The Image object is not being set correctly if it is not being read correctly.
Additionally, the if the Image object in the PictureBox control is replaced with a new one, the new one must be inserted before the old one is Disposed (even if it is just a constant) to avoid a .NET exception as in the following examples (from the Image Manipulation DotNET zip):
01-29-2021 06:18 PM
@ThamS wrote:
any better Idea?
so, the error ocurs, when the image data is meant to be saved to the Memory Stream ... how annoying
in contrast to the knowledgebase article, you don't close the Image Reference - as rwunderl mentioned in post 3
maybe you also need to add the Image.Dispose method - as rwunderl mentioned in post 6
does this have any effect, e.g. is the refnum of the image still 0?
01-29-2021 07:50 PM
@alexderjuengere wrote:
so, the error ocurs, when the image data is meant to be saved to the Memory Stream ... how annoying
The error happens at the Save method because that is the first time you are trying to use the Image object. My argument is that the PictureBox does not have a valid Image object in the first place, and THAT is why the error occurs. You could run the PicBox to PNGstring vi with no inputs at all and get the 1172 error "System.ArgumentNullException" from .NET.
@alexderjuengere wrote:
does this have any effect, e.g. is the refnum of the image still 0?
Disposing and Closing are good things to do, but they will not retroactively make the refnum valid.
In the example I first directed you to, the Image object of the PictureBox is created from an image file on disk:
This is a valid Image object. The Image object is then set to the PictureBox in the Display Image function:
Now the PictureBox has a valid Image object. Then later on when Image is read to invoke the Save method, it is still going to be a valid Image object.
Your Save will never work, because the Image object is invalid. We have determined that. Where is your application generating and setting the Image of the PictureBox? That is what I am trying to get you to debug. That is what is broken.
01-31-2021 09:53 PM
Hi rwunderl
Thank you for your both effort so far.
I think my probelm is, the VLC activeX seems doesn't really create image on picture box. instead it just use the windows handler of the .NET picturebox to show the frame on top of picturebox control. (I'm refereing to VLC scripting in LabVIEW by GriffinRU)
what do you guys think?
I attached my code project in rar.
02-03-2021 06:29 AM