Jump to content
GregPayne

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. 

 

post-25191-0-16493900-1401202572_thumb.p

 

I have also attached the vi if you interested. 

 

Cheers, 

Greg

Opacity Trace.vi

Share this post


Link to post
Share on other sites

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.

post-7375-0-78470600-1401209237_thumb.pn

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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?

post-7375-0-74618600-1401263856_thumb.pn

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
It would be nice if all of the VIs in the NI_WebServices.lvlib were not password protected.  :nono:

 

That would be nice. I think NI has started opening some of their vi's so they might get there eventually.

Share this post


Link to post
Share on other sites

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.