Re: To change Background in MATLAB GUI



On Mar 17, 6:30 pm, "Scott Burnside" <n...@xxxxxxxx> wrote:
sindhu...@xxxxxxxxx wrote in message <2bfb661b-f92e-429a-

8bca-197454d60...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...

How can one change the background to a picture in MATLAB
GUI? I mean,
I want a picture in the background instead of the static
colour
background.

Piece of Cake:

% pick a file
[filename, pathname] = uigetfile('*.jpg','Pick a JPEG');
% read image data
img = imread([pathname filename]);
% Display the image on a figure
sz = size(img);
screensize = get(0,'ScreenSize');
% center the figure on the screen
xpos = ceil((screensize(3)-sz(2))/2);
ypos = ceil((screensize(4)-sz(1))/2);
hi = figure('position',[xpos, ypos, sz(2),sz(1)],...
            'units', 'pixels',...
            'renderer', 'painters',...
            'MenuBar', 'none');
set(gcf,'PaperPositionMode','auto');
imagesc(img);
set(gca,'Position',[0, 0, 1, 1]);
axis image off;
% end of code snippet

hth,
Scott

Scott:
Isn't this simply displaying an image in a figure? Sure you can do
that but then how do you place all the various other controls that you
need to make a full-fledged application like radio buttons, push
buttons, listboxes, etc.? I tried making such a GUI with GUIDE and
then setting the current figure to the main GUI window handle and then
calling imshow to try to make the main figure window (i.e. the main
dialog box) be the image and have all the other controls (buttons,
listboxes, etc.) rest on top of that but it didn't work. It just
ignored the imshow and left the background as plain gray.

But then I took the code Steven mentioned :
% 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);

and stuck it in the *_OpeningFcn function of the main macro (this
function is automatically created by GUIDE) and that seemed to do the
trick. I had the eight.tif image in the background and all the other
controls on top of it.
Regards,
ImageAnalyst
.