--- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
hObject handle to pushbutton1 (see GCBO)
eventdata reserved - to be defined in a future version of MATLAB
handles structure with handles and user data (see GUIDATA)
I=imread('pic_gui_I.bmp','bmp');
axes(handles.axes1);
image(I)
axis off;
mp= handles.activex1; % activex1 为调用的WMP的handle。
%画图后:
h=imrect;%鼠标变成十字,用来选取感兴趣区域
----------------------------------------
%图中就会出现可以拖动以及改变大小的矩形框,选好位置后:
----------------------------------------
pos=getPosition(h);
----------------------------------------
%pos有四个值,分别是矩形框的左下角点的坐标 x y 和 框的 宽度和高度
----------------------------------------
----------------------------------------
%拷贝选取图片
----------------------------------------
imCp = imcrop( I, pos );
figure(2)
imshow(imCp);
2. 返回鼠标坐标点
functionmain()global line;
global h1;
global flag;
flag=0;
line=rand(1,100);
h1=plot(line);
hold on
set(h1,'ButtonDownFcn',@clicky);
h2 = uicontrol('style','text','Position',[301510030],'string','此处显示选中点的坐标');
functionclicky(varargin)%鼠标点击时触发该事件global h_point
global line;
global flag;
if flag
set(h_point,'Visible','off');
end
a=get(gca,'Currentpoint');
fori=1:2
ai=a(1,i);
ifceil(ai)-ai>ai-floor(ai)
b(1,i)=floor(ai);
else
b(1,i)=ceil(ai);
endend
h_point=plot(gca,b(1,1),line(b(1,1)),'r*');
if ~isempty(h_point)
flag=1;
end
set(findobj('style','text'),'String',strcat('x:',num2str(b(1,1)),' y:',num2str(line(b(1,1)))));