How to display a transparent image in a UIFigure

3 views (last 30 days)
What is the best way to display an image with transparency in a UIFigure ? 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Jan 2024
Edited: MathWorks Support Team on 23 Jan 2024
It is possible to display a transparent image by using a UIAxes object and by making sure to retain the alpha data when reading and displaying the image. The code bellow shows an example on how this can be achieved:
fig = uifigure;
ax = uiaxes(fig);
[imdata, ~, imalpha] = imread('myimage.png');
image(imdata, "AlphaData", imalpha, "Parent", ax);
ax.Visible = "off";
It is then possible customize the axes further (for instance "ax.Position" allows to set the positions and dimensions of the image). The following page of the documentation lists the UIAxes properties that can be used: 
https://www.mathworks.com/help/matlab/ref/matlab.ui.control.uiaxes-properties.html

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!