Jump to content

Create pictures with different opacity levels


Recommended Posts

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): 

 

post-25191-0-64022500-1401195490.png

 

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

Link to comment

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.

Link to comment

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

Link to comment

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

Link to comment

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.

Link to comment
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.  :nono:

Link to comment
  • 7 years later...

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
Link to comment
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?!

Link to comment
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.

Link to comment

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 by Aristos Queue
Link to comment

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.

image.png.627620ed856a731ffc2f4540c47604de.png

Make Control Glow.vi Offset Glow Rect.vi

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Taylorh140
      I have never gotten the performance that I desire out of the 2D picture control. I always think that it should be cheaper than using controls since they don't have to handle user inputs and click events etc. But they always seem to be slower.
      I was wondering if any of the wizards out there had any 2d picture control performance tips that could help me out?
      Some things that come to mind as far as questions go:
      Is the conversion to from pixmap to/from picture costly?
      Why does the picture control behave poorly when in a Shift register?
      What do the Erase first settings cost performance wise?
      Anything you can think of that are bad ideas with picture controls?
      Anything you can think of that is generally a good idea with picture controls?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.