1
votes

I am trying to use PNG images as Toolbar icons. I am currently reading them with imread an set the corresponding CData value.

Now I have some images with transparency. There is no alpha channel (I found some threads with solutions for that), but I get some kind of "Simple Transparency". The imfread function returns "simple" for the Transparency field and a vector of values between 0 and 1 for the SimpleTransparencyData field.

I couldn't find any information about this transparency type neither in the Matlab help nor the internet. So I would like to know if it is possible to show the transparent image in the toolbar directly, or if not how to composite the transparent values with the toolbar's background color.

2

2 Answers

1
votes

In summary you set the CData value to be a NaN to represent transparency.

See this article that I wrote on undocumentedmatlab.com which describes how to do it for uicontrols.

For a toolbar icon you modify the CData property in the same way - the primary difference is that you dont need to modify the backgroundcolor property.

0
votes

I did a quick test on the only solution I could probably imagine and it really seems to work:

I forgot to mention, that I am using indexed PNG files for this. But this sort of transparency seems to imply this fact.

The indexed colors are ordered that the (partially) transparent colors are at the beginning of the table. The SimpleTransparencyData now specifies the transparency of each of the indexed colors. Non-transparent colors are left out, as there are more colors than transparency values.

With that additional information it is easy to composite a single background color with the image.