See the attached VI. I'm using some .Net code to resize an image, lacking the $5k for IMAQ.
It instantaneously writes to a picturebox, but because I'm not using the Paint event it goes away when it is redrawn. So when you run it, it will appear to flicker. That's fine; I don't care about rendering to a Picturebox, I jsut want the image after it's been resized.
My question is, after I call DrawImage, how do I get that image into some format labview can use? Saving to a file & loading it is not an option. I tried pasting it to the clipboard using ClipBoard.SetImage but that results in an error:
Inner Exception: System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.)
I have no idea what this means.
Any help is greatly appreciated!
Solved! Go to Solution.
Please ignore the silly error in my VI. Forgot to enable a subdiagram in diagram disable structure.
Looks like a better way to rescale in .NET is to use the ScaleTransform method, instead of Draw. (EDIT: never mind, I misunderstood what ScaleTransform does)
As for the error with the clipboard, try setting the VI to run in the User Interface execution subsystem, which forces it to run in a single thread. This often resolves threading problems with .NET and ActiveX components.
Thanks guys. Both good answers, and I've got it working now.
MemoryStreams are one way to do it.
I have memory usage problem with your GDI Resize.vi 22KB
I call these vi from main vi and after every call memory usage increase for ~50MB (which could be uncompressed size of my 4032 x 3024 jpeg with 4 bytes for pixel). Sub vi is not reentrant.
Because I want to resize around 100 pictures these is a problem.
My bad. Dispose of the Bitmap object created from the path control and the Graphics object which is output from the FromImage terminal of the constructor. Use the error connection so that the Dispose method is called at the end (at the same time the MemoryStream is disposed of). I rip these examples from other places and sometimes miss an important piece.
Thanks. It's much better, but in the case of 50 pictures 4032 x 3024, 1GB of RAM usage is still being collected. With Resize off there is no Memory usage rise.
It sounds like you're allocating new memory for each picture, is there some wire/input to reuse buffers?
I do not understand you. I thing that vi is clear. If resize is not performing, there is no memory problem.