matlab简易画板

function varargout = example6_3_3(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @example6_3_3_OpeningFcn, ...
                   'gui_OutputFcn',  @example6_3_3_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

function example6_3_3_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

setappdata(hObject, 'isPressed', false);
cData = imread('loading.jpg');
image(cData);
set(handles.axes1, 'colororder', [0 0 1], 'units', 'normalized', 'position', [0 0 1 1])

guidata(hObject, handles);

function varargout = example6_3_3_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
if strcmp(get(gcf,'selectiontype'),'alt')
    delete(findobj('type', 'line', 'parent', handles.axes1));
elseif strcmp(get(gcf,'selectiontype'),'open')
    col=uisetcolor(get(handles.axes1,'colororder'),'选择画笔颜色');
    set(handles.axes1,'colororder',col)
else
    pos=get(handles.axes1,'currentpoint');
    setappdata(hObject, 'isPressed', true);
    set(hObject, 'UserData', pos(1,[1,2]));
end

function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
isPressed = getappdata(hObject, 'isPressed');
pos = get(handles.axes1, 'currentpoint');
if isPressed 
    pos1 = get(hObject, 'UserData');
    line([pos1(1); pos(1, 1)],[pos1(2); pos(1, 2)], 'linewidth', 4);
    set(hObject, 'UserData', pos(1,[1,2]));
end

function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
setappdata(hObject, 'isPressed', false);


书上的代码,贴出来学习下。(画上的话是豪仔刚跟我说的,广东人常这么说咩?哈哈)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值