简单的源码(好久没写matlab代码了,也没测试,要改应该也很容易):
img
=
imread('img.jpg')
//假设图片是二维的灰度图片
logo
=
imread('logo.jpg')
//假设也是二维的
new_img
=
img
new_img[1:size(logo,1),
1:size(logo,2)]
=
a
*
img[1:size(logo,1),
1:size(logo,2)]
+
b
*
logo
a和b可以自己设置,只要a+b=1就行了。如果要logo明显,就把b设的大些。
具体实现方法,其实十分简单,只需要一个函数chgicon.m该函数用红色文字表示:
function chgicon(h,filename)
%CHGICON changes the figure icon.
%
CHGICON(H,FILENAME) changes the icon of a figure to an image specified by
%
the string FILENAME, where H is a handle to the figure. If the file is not
%
in the current directory or in a directory in the MATLAB path,specify the
%
full pathname of the location on your system. If FILENAME is not a valid
%
image file name, the function just removes the previous icon of the figure.
%
%
Example:
%
h = figure
%
chgicon(h,'newIcon.png')% replace 'newIcon.png' with your image
%
% IMPORTANT NOTES:
%
REPLACING THE MATLAB GUI ICON VIOLATES THE LICENSE AGREEMENT
% OF MATLAB. DO NOT USE THIS FUNCTION COMMERCIALLY.
%
%
Han Qun, Sept. 2005
%
Copyright 2005-2006 Han Qun
%
College of Precision Instrument and Opto-Electronics Engineering,
%
Tianjin University, 300072, P.R.China.
%
Email: junziyang@126.com
%
$Revision: 1.0 $
$Date: 2005/12/2 $
if nargin<2
error('MATLAB:chgicon','%s','Too few input arguments!')
end
if nargin >2
error('MATLAB:chgicon','%s','Too many input arguments!')
end
newIcon = javax.swing.ImageIcon(filename)
javaFrame = get(h,'JavaFrame')
javaFrame.setFigureIcon(newIcon)将上面的函数保存在自己要使用的路径下,再调用即可。
调用语句:
h = figure
chgicon(h,'12.jpg')
就可以了。
再推广到GUI上也是一样的,只要在Create Fcn中调用这个函数就可以了:
function figure1_CreateFcn(hObject, eventdata, handles)
% hObjecthandle to figure1 (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handlesempty - handles not created until after all CreateFcns called
chgicon(hObject,'12.jpg')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)