Transparent PNG file on background in Matlab GUI
11 次查看(过去 30 天)
显示 更早的评论
Hello,
For my GUI i have set a background image and now I want to put a (partly) transparent PNG image on a pushbutton on top of this background image, while keeping the background visible in the parts where the button image is transparent. How do I do this?
Thanks in advance!
0 个评论
回答(3 个)
Robert Cumming
2014-12-12
I know this is an old post - but if anyone comes across this you may be interested in this blog on undocumentedmatlab
0 个评论
Walter Roberson
2012-6-5
You cannot do this directly. The uicontrol() that can have images placed on them (such as pushbutton) have a CData property that must be truecolor (RGB) values, but there is no alpha property, so there is no way to define transparency for such images.
The work-around is to figure out which part of the background image the button would be covering up, and to store the corresponding pixel values into the image array locations that should be transparent, and then to use that as the CData.
Ideally you would re-do this when the figure was resized; that would have to be triggered off of the figure resize callback, as uicontrol do not have a resize callback.
2 个评论
Walter Roberson
2012-6-6
I suspect bg_image is 3 dimensional (truecolor, RGB) rather than 2 dimensional. You probably need to add a third index when extracting bg_button
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!