LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

problem with loading a transparent image onto Labview FP proggrammatically

Hi all,

 

I have a .png logo with transparent background, and I want to load it onto labview FP prorgrammatically. My problem is, if I load it programmatically (read image, display on image display), the background won't be transparent any more. But if I import it and paster it on labview FP manually, it looks OK.

 

I tried picture and it doesn't work.

 

Any idea? How to do it?

 

Thank you for any help.

 

Anne Zuo

 

0 Kudos
Message 1 of 6
(4,116 Views)

Anne,

 

I am assuming when you say you are loading the image programatically, that you are sending it to a picture control/indicator.  This works differently than just dragging an image onto the front panel to create decorations.

 

When the image is programatically unflattened, it loses the alpha channel.  There is a workaround in the attached link, but I still don't think this is what you are looking for, as it sounds like you are just trying to programatically add decorations to the front panel.  The picture controls will still have a border around them, so transparency is not really the best solution.  Take a look at this forum post:

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=257539&requireLogin=False

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 2 of 6
(4,081 Views)

You can sort of do it if you an image of the background as well (e.g. if you capture an image of the panel when the picture control is empty). As mentioned, the alpha channel is actually read from the PNG file, so what you need to do is average each component of each pixel with the data from the other image, but use the alpha information as a weight.

 

The code to do this is actually relatively simple (I already did it so I know, although I can't post it) - you need to get the image as a 2D array of U32 and then do a couple of Split Number operations, which will give you the RGB data as a set of 2D U8 arrays. You can then calculate the difference between each component of each pixel in the two pictures and multiply that by the ratio of the transparency (which either goes 0-100 or 0-255, I don't remember). You can then call Join Number to get the U32 array back, which you can wire into Draw Unflattened Pixmap.

 

You can also get rid of the picture control border by using a classic picture control or by right clicking the 3D frame and pressing the space bar a couple of times in the color dialog. This toggles between FG and BG colors and will allow you to color the frame transparent.


___________________
Try to take over the world!
Message 3 of 6
(4,075 Views)

I am not trying to create an image with transparent backgound, I already have the image. The problem is how to import it onto LabVIEW FP

programmatically, keeping the same transparency.

 

From the image data cluster after Read PNG File.vi, I can see the image type is 0 and image depth is 8.

 

 

So far, I didn't see any good solution.  Smiley Mad

 

 

Anne

0 Kudos
Message 4 of 6
(4,059 Views)

Sorry no code to share but this I have used....

 

Classic pic like tst mentioned paint frame AND background transparent.

 

Create an approprait mask for the image and then use Draw Flattened Pixmap a picture for the picture.

 

Using that method I was able make it look like you were dropping objects on the FP.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 6
(4,051 Views)

What I suggested would preserve the transparency. The only catch is that you have to implement it yourself, since the picture control does not support alpha transparency, only masking.

 

In any case, you should note that an image depth of 8 is probably wrong, unless you're using a mask or your image is monochromatic and you're only using that byte as an alpha channel. If you have an image with a depth of 32, you can extract the transparency byte for each pixel (which is every fourth element of the image array, so you can just use Decimate Array and resize it to have 4 terminals). As I mentioned, the code for doing this is fairly simple and compact, since the primitives can handle the entire array.


___________________
Try to take over the world!
Message 6 of 6
(4,039 Views)