Transparent PNG file on background in Matlab GUI

조회 수: 28 (최근 30일)
Frank . 2012년 6월 5일
댓글: Serge . 2022년 11월 6일
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!

답변 (3개)

Robert Cumming
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

Klont 2015년 7월 26일
편집: Klont 님. 2015년 7월 26일
Simply make a matrix of size height (pixels) x width (pixels) x 3 (rgb) of doubles between 0 and 1, with NaN indicating transparency.
  댓글 수: 1
Serge 2022년 11월 6일
This works if you are happy with alpha being all or nothing...

댓글을 달려면 로그인하십시오.

Walter Roberson
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
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 CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by