How do I add a background image to my GUI or figure window?
136 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 5 de Feb. de 2013
Comentada: Walter Roberson
el 2 de Abr. de 2020
The MATLAB demo window has a background image in it, and I would like to put a background image in my figure.
Respuesta aceptada
MathWorks Support Team
el 5 de Feb. de 2013
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 comentarios
Walter Roberson
el 2 de Abr. de 2020
Set the axes Layer property to 'top'
By default, the axes is always drawn below any object in the same axes.
Más respuestas (1)
Ka Mirul
el 17 de Oct. de 2017
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 comentarios
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!