How do I add a background image to my GUI or figure window?
136 次查看(过去 30 天)
显示 更早的评论
The MATLAB demo window has a background image in it, and I would like to put a background image in my figure.
采纳的回答
MathWorks Support Team
2013-2-5
The following code will let you create a background image in your figure. To do this, you need to create an axes object that spans the size of the figure, and then place the image inside this axes.
% This creates the 'background' axes
ha = axes('units','normalized', ...
'position',[0 0 1 1]);
% Move the background axes to the bottom
uistack(ha,'bottom');
% Load in a background image and display it using the correct colors
% The image used below, is in the Image Processing Toolbox. If you do not have %access to this toolbox, you can use another image file instead.
I=imread('eight.tif');
hi = imagesc(I)
colormap gray
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(ha,'handlevisibility','off', ...
'visible','off')
% Now we can use the figure, as required.
% For example, we can put a plot in an axes
axes('position',[0.3,0.35,0.4,0.4])
plot(rand(10))
In a GUI .m file created by GUIDE, the easiest place to put this code is in the "CreateFcn" for the figure window. This will cause it to be executed when the GUI is created.
One problem which may arise is due to the handle visibility of the GUI. If a new figure window appears when you execute this code in your GUI, please change the HandleVisibility property of the GUI figure as described in the solution attached at the bottom of this page.
If you want to change the transparency of this background image, you can set the "AlphaData" property of the image. An example of how to do this is shown in the example code below:
set(hi,'alphadata',.5)
Please note that this will not change the transparency of the GUI or the figure window.
3 个评论
Walter Roberson
2020-4-2
Set the axes Layer property to 'top'
By default, the axes is always drawn below any object in the same axes.
更多回答(1 个)
Ka Mirul
2017-10-17
Hallo, I have seen a tutorial about "Set an Image as GUI Background" at https://www.youtube.com/watch?v=-qjwVjrnrWU and it works. Hope it will help you.
0 个评论
另请参阅
类别
在 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!