Having a logo or picture on my own GUI

4 次查看(过去 30 天)
I have been trying to add a picture or logo to my own built GUI. Despite advices picked up from another thread I have been unsuccessful, mostly due to my lack of understanding how different built in functions such as handles, callbacks, etc work. Here is a brief description: I like to be able to type in a file name that I can use to output my results into. Then there are two buttons to perform different tasks. Now, I have not quite figured out how to inquire for the output file name and definitely I do not know how to have a logo image on this gui. What you see is my understanding of what has been posted on another thread. Thanks for your advice.
function varargout = FastDD(varargin)
% FastDD M-file for FastDD.fig
% FastDD, by itself, creates a new FastDD or raises the existing
% singleton*.
%
% H = FastDD returns the handle to a new FastDD or the handle to
% the existing singleton*.
%
% FastDD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FastDD.M with the given input arguments.
%
% FastDD('Property','Value',...) creates a new FastDD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FastDD_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FastDD_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help FastDD
% Last Modified by GUIDE v2.5 23-Apr-2012 18:09:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FastDD_OpeningFcn, ...
'gui_OutputFcn', @FastDD_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before FastDD is made visible.
function FastDD_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FastDD (see VARARGIN)
% Choose default command line output for FastDD
handles.output = hObject;
MyImage=imread('reza.jpg');
imshow(MyImage, 'Parent', handles.axesImage);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FastDD wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = FastDD_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in RunTask.
function RunTask_Callback(hObject, eventdata, handles)
% hObject handle to RunTask (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in CalcDD.
function CalcDD_Callback(hObject, eventdata, handles)
% hObject handle to CalcDD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function SubjData_CreateFcn(hObject, eventdata, handles)
% hObject handle to SubjData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function SubjData_Callback(hObject, eventdata, handles)
% hObject handle to SubjData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%FileID = get(hObject,'String');
function varargout = FastDD(varargin)
% FastDD M-file for FastDD.fig
% FastDD, by itself, creates a new FastDD or raises the existing
% singleton*.
%
% H = FastDD returns the handle to a new FastDD or the handle to
% the existing singleton*.
%
% FastDD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FastDD.M with the given input arguments.
%
% FastDD('Property','Value',...) creates a new FastDD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FastDD_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FastDD_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help FastDD
% Last Modified by GUIDE v2.5 23-Apr-2012 18:09:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FastDD_OpeningFcn, ...
'gui_OutputFcn', @FastDD_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before FastDD is made visible.
function FastDD_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FastDD (see VARARGIN)
% Choose default command line output for FastDD
handles.output = hObject;
MyImage=imread('reza.jpg');
imshow(MyImage, 'Parent', handles.axesImage);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FastDD wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = FastDD_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in RunTask.
function RunTask_Callback(hObject, eventdata, handles)
% hObject handle to RunTask (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in CalcDD.
function CalcDD_Callback(hObject, eventdata, handles)
% hObject handle to CalcDD (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function SubjData_CreateFcn(hObject, eventdata, handles)
% hObject handle to SubjData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function SubjData_Callback(hObject, eventdata, handles)
% hObject handle to SubjData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%FileID = get(hObject,'String');

采纳的回答

Image Analyst
Image Analyst 2012-4-24
Put this code in your FastDD_OpeningFcn() function to display an image in an axes on your GUI called axesImage:
% Read in a reza's color logo image.
% Prepare the full file name.
folder = pwd;
baseFileName = 'reza.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check for existence. Warn user if not found.
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
end
else
% Read it in from disk.
rgbImage = imread(fullFileName);
% Display the original color image.
axes(handles.axesImage);
imshow(rgbImage, []);
title('Reza Logo Image', 'FontSize', 20);
end

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2012-4-24
Can you show us a screenshot of your GUI in GUIDE and point to the axes where you want your logo to go?
It should be a little axes where you want your logo, retagged to something like axLogo. Then in the opening function, something along the lines of:
I = imread('logo.jpg');
imshow(I,'parent',axLogo);

标签

Community Treasure Hunt

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

Start Hunting!

Translated by