下列代碼對鼠標事件進行處理,,若鼠標左鍵按下,,則在鼠標按下位置繪制一個方框;若其它鼠標鍵按下,,則退出鼠標處理循環(huán),。 ------------------------------------------------ figure;imshow(im); hold on; x=[]; y=[]; wintx=5; winty = 5 for count = 1:100000 [xi,yi,button] = ginput(1);%鼠標左鍵 if button == 1 plot(xi + [wintx+.5 -(wintx+.5) -(wintx+.5) wintx+.5 wintx+.5],yi + [winty+.5 winty+.5 -(winty+.5) -(winty+.5) winty+.5],'-','color',[ 1.000 0.314 0.510 ],'linewidth',2); x = [x;xi]; y = [y;yi]; drawnow; else%其它鼠標鍵按下 break; end end hold off
|
|