GregPayne Posted May 27, 2014 Report Share Posted May 27, 2014 Hi Everyone, I am trying to create a picture in LabVIEW that records a trace. I want to get the concept working first before I add it to my program. I would like the end result to look something like this (I used Inkscape to create this image): So the idea is a trace gets made with the opacity of the point set quite low (in the above case 0x48). Therefore when the same coordinate is passed over for a second time, the point gets darker. The darkness of the points will indicate which coordinate is passed over the most number of times. At the moment I am using a 2D Picture indicator and drawing the mouse coordinates, but can't set the opacity, only RGB. Is there another function that the opacity can be set? Thanks, Greg Opacity Trace.vi Quote Link to comment
hooovahh Posted May 27, 2014 Report Share Posted May 27, 2014 There are other members on the forums with more experience then I. But what I do know is that LabVIEW doesn't really support transparency. It does support the data, but not displaying the alpha layers. http://digital.ni.com/public.nsf/allkb/00736861C29ADFB786256D120079D119 Because of this there are many tricks people have come up with to get around this like reading the color of the background, then merging color of the background with the alpha layer to come up with a pretend color that looks semi transparent. Other trick involve using the Windows .NET PictureBox control which does support alpha layer information. I've had success with using this in the past but only to display already made images that had alpha characteristics. Quote Link to comment
GregPayne Posted May 27, 2014 Author Report Share Posted May 27, 2014 Thanks, I have just come across a similar article so might have to look at another way of doing this. Will look into the .NET picture box and see how that goes. Quote Link to comment
GregPayne Posted May 27, 2014 Author Report Share Posted May 27, 2014 For any one that is interested, here is how I got this working. As hooovahh suggested, I used a .net picturebox and it is working well. Still need to add some tweaks, but the functionality is there. I have also attached the vi if you interested. Cheers, Greg Opacity Trace.vi Quote Link to comment
Neil Pate Posted May 27, 2014 Report Share Posted May 27, 2014 Looks neat. Am going to tinker with this .net control too if I get a chance. Just a heads up, I know this was just a proof of concept, but you probably don't want to be creating all those objects inside the loop. Quote Link to comment
GregPayne Posted May 27, 2014 Author Report Share Posted May 27, 2014 Thanks Neil, Good point about creating the objects outside of the loop. I didn't even think about that... eek Quote Link to comment
GregPayne Posted May 27, 2014 Author Report Share Posted May 27, 2014 My next step was to save the picturebox to an image. This was trickier than I expected. I kept getting a .net exception when trying to save the picturebox image. After reading through a few forums and code examples, I found out that it is not particularly good practice to draw directly into a picturebox. The better way is to create a bitmap inside the picturebox and then draw onto the bitmap. Then all you need to do is call the bitmap.save() method and an image is saved. I have attached my latest vi that saves the image drawn. I also added a timestamp and file path to the image before it is saved. The code is not very clean, so sorry. I'll be cleaning it up when adding it the the bigger application. Cheers, Greg Opacity Trace_3.vi Quote Link to comment
hooovahh Posted May 27, 2014 Report Share Posted May 27, 2014 If you are interested in getting your image back into a LabVIEW data type you can use the VI I attached. Provide the Image from the PictureBox and you'll get the Image Data back out in PNG format. From here you can perform a save and I believe transparency will be kept. If you try to display the this image in a 2D Picture the transparency will be lost. Using this PNG to Stream or Stream to PNG dance you can go to and from the picturebox and system drawing tools, to the LabVIEW tools and back. Get Image Data From PictureBox.vi Quote Link to comment
GregPayne Posted May 28, 2014 Author Report Share Posted May 28, 2014 Would you mind saving it for LV2010? That is all I have at work so can't open this vi. Thanks, Quote Link to comment
Neil Pate Posted May 28, 2014 Report Share Posted May 28, 2014 Would you mind saving it for LV2010? That is all I have at work so can't open this vi.Thanks, Greg, I do not have 2010 installed either, but here is a picture maybe you can recreate it from this? Quote Link to comment
hooovahh Posted May 28, 2014 Report Share Posted May 28, 2014 Saved in 2010 Get Image Data From PictureBox 2010.vi Quote Link to comment
GregPayne Posted May 28, 2014 Author Report Share Posted May 28, 2014 Thank you for saving it in LV2010. Unfortunately I can't run it as I don't have NI_WebServices.lvlib. I am guessing it is not included in LabVIEW 2010 base. Will give it a go at home later where I have LV2013. Quote Link to comment
mje Posted May 28, 2014 Report Share Posted May 28, 2014 The offending call would be NI_WebServices.lvlib:PNG Data to LV Image.vi. It converts a byte array to the LabVIEW imagedata.ctl cluster typedef. Without that VI, I think the only built in way around it will be to save the data to disk and use the Read PNG File.vi method. Not sure if this would be too slow for you. Why the memory version of the PNG converter is in a non-base library but the disk version is is beyond me. Ridiculous if you ask me. Quote Link to comment
Neil Pate Posted May 28, 2014 Report Share Posted May 28, 2014 The offending call would be NI_WebServices.lvlib:PNG Data to LV Image.vi. It converts a byte array to the LabVIEW imagedata.ctl cluster typedef. Without that VI, I think the only built in way around it will be to save the data to disk and use the Read PNG File.vi method. Not sure if this would be too slow for you. Why the memory version of the PNG converter is in a non-base library but the disk version is is beyond me. Ridiculous if you ask me. It would be nice if all of the VIs in the NI_WebServices.lvlib were not password protected. Quote Link to comment
GregPayne Posted May 28, 2014 Author Report Share Posted May 28, 2014 It would be nice if all of the VIs in the NI_WebServices.lvlib were not password protected. That would be nice. I think NI has started opening some of their vi's so they might get there eventually. Quote Link to comment
Aristos Queue Posted September 14, 2021 Report Share Posted September 14, 2021 New in LabVIEW 2020: C:\Program Files (x86)\National Instruments\LabVIEW 2020\vi.lib\picture\PNG\Draw Flattened Blended Pixmap.vi I didn't create this one. It is not in the palettes. I have asked that it be added in a future version. 2 Quote Link to comment
hooovahh Posted September 14, 2021 Report Share Posted September 14, 2021 Super cool! I've often used a very hacky solution for this usually involving lots of extra .Net and PictureBox functions, then saving to memory buffers, that I'd then said to LabVIEW to get pushed to a 2D Picture control. This makes this much, much easier. And I was surprised it handled multiple transparent images on top of each other well. I'd love to see this on the palette maybe even along with some other PNG related functions like: Add LV Image to PNG Data.vi and PNG Data to LV Image.vi Both of these found under C:\Program Files (x86)\National Instruments\LabVIEW 2020\vi.lib\wsapi\VIs\ Add Create Mask By Alpha.vi Found here but might not be as important if Draw Flattened Blended gets added C:\Program Files (x86)\National Instruments\LabVIEW 2020\vi.lib\picture\picture.llb\Create Mask By Alpha.vi Expose the compression input to the LV Image to PNG Data Quote Link to comment
ShaunR Posted September 15, 2021 Report Share Posted September 15, 2021 6 hours ago, Aristos Queue said: New in LabVIEW 2020: C:\Program Files (x86)\National Instruments\LabVIEW 2020\vi.lib\picture\PNG\Draw Flattened Blended Pixmap.vi I didn't create this one. It is not in the palettes. I have asked that it be added in a future version. Hmmm. Can't back-save a non password protected VI? That's new ... and how do I set my VI's to do that?! Quote Link to comment
hooovahh Posted September 15, 2021 Report Share Posted September 15, 2021 12 hours ago, ShaunR said: Hmmm. Can't back-save a non password protected VI? That's new ... and how do I set my VI's to do that?! I've seen this a few times, and you probably already realize the simple solution is to just Select All >> Copy >> New VI >> Paste. This loses the VI description and icon which can be manually added. Still I agree it is weird that some VIs are harder to back save for some reason. Quote Link to comment
Aristos Queue Posted September 15, 2021 Report Share Posted September 15, 2021 (edited) You can't save for previous anything inside vi.lib. Just do Save As >> Copy to a new location and then save that for previous. (It's been that way longer than I've worked on LabVIEW, and I just realized I have never asked why. It's just "one of those things" that I picked up early in my career that became part of the mental landscape.) Edited September 15, 2021 by Aristos Queue Quote Link to comment
Aristos Queue Posted September 15, 2021 Report Share Posted September 15, 2021 Here is a helper routine that I wrote yesterday based on the other VI. It's the world's most inefficient way to draw a rectangle but it works, and if you're trying to do some sort of animation fade effect, you can do it with this by putting in decreasing opacity. Draw Blended Rectangle.vi 1 Quote Link to comment
ShaunR Posted September 15, 2021 Report Share Posted September 15, 2021 4 hours ago, Aristos Queue said: You can't save for previous anything inside vi.lib. Just do Save As >> Copy to a new location and then save that for previous. I know this trick and it used to work but it seems to now be marked as a "toolkit" VI and it doesn't matter where you save it. Quote Link to comment
Aristos Queue Posted September 17, 2021 Report Share Posted September 17, 2021 Another VI I thought someone reading this forum thread might find helpful. This one calls the one I posted previously as a subVI. "Make Control Glow.vi" draws a fading rectangle behind the specified control. Save it and its subVI ("Offset Glow Rect.vi") to the same subdirectory. For example, here's a glow on a system OK button. Color and border thickness are parameterized. Saved in LV2020. Make Control Glow.vi Offset Glow Rect.vi Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.