LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create transparent PNG using "Write PNG File.vi"

According to the documentation, you can create a transparent png file using the "image data.mask" element of "Write PNG File.vi". As far as I can tell, the mask is completely ignored: images created with mask set to an empty array are bytewise-identical to those created with a mask that is a mix of 1s and 0s. Has anyone successfully created a PNG image with transparency using this function?

 

I'm using LV 2009 SP1.

 

-Rob 

0 Kudos
Message 1 of 5
(7,723 Views)

Where in the help (labVIEW 2009 version) do you find that info?

 

Don't be fooled by the Type description of the image cluster, that only describes how the image indicator deals with it. I think that if you want to create a PNG with transparency info you should set the upper byte of the 24-bit (actual 32 bit) image format.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 5
(7,714 Views)

Hi Rob,

 

here's some quick mock up of what I'm talking about.

 

It produces a valid PNG and using paint.net I feel it is what I expected, but I am not sure.

 

Transparency layer.png

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 3 of 5
(7,704 Views)

Thanks to Ton I have gone and learned something today.  A few years back (I have lost count) I wrote a set of PNG encoders/decoders because LV support for PNG files was marginal at best.  No alpha support, no buffer based manipulation, just file reading and writing (of certain types).  As such I have eschewed the LV VIs for the most part.  Now it seems that you can at least trick LabVIEW into writing the transparency information.

 

If you specify a bit depth of 32, the image array is arranged alpha-R-G-B for each pixel.  If you have a mask, you can convert it to a 1-bit pixmap and use alpha values of 255 or 0 for each pixel, and at least have crude transparency.  Here is my (now much simplified) VI to save the image data with transparency.  If you give it a 24-bit image with a non-empty mask array it will add the proper values to the alpha channel and promote the image to 32-bit for saving.  

 

 

Message 4 of 5
(7,664 Views)
How funny, I just googled for "png transparency labview", came across my own post and, better yet, Daren K's library. It works great and is a drop-in replacement for the vi.lib function!
0 Kudos
Message 5 of 5
(6,939 Views)