Creating Graphical User Interfaces |
Example: Displaying an Image File
This example shows how to display an image file on a GUI. The example
set(hObject, 'Units', 'pixels'); handles.banner = imread([matlabroot filesep 'demos' filesep 'banner.jpg']); % Read the image file banner.jpg info = imfinfo([matlabroot filesep 'demos' filesep 'banner.jpg']); % Determine the size of the image file position = get(hObject, 'Position'); set(hObject, 'Position', [position(1:2) info.Width + 100 info.Height + 100]); axes(handles.axes1); image(handles.banner) set(handles.axes1, ... 'Visible', 'off', ... 'Units', 'pixels', ... 'Position', [50 50 info.Width info.Height]);
When you run the GUI, it appears as in the following figure.
The preceding code performs the following operations:
banner.jpg
using the command imread
.
imfinfo
.
info.Width
and info.Height
, respectively. The width and height of the GUI are the third and fourth entries of the vector position
.
image(handles.banner)
.
How the GUI and Dialog Work | Selecting GUI Options |