首先看看效果

首先功能说明下,运行后通过myfile菜单打开一幅图片之后在axes中显示,由于要使用图片的放大缩小等功能将figure 的菜单栏与工具栏都一并打开了。

界面编程主要是callback函数编写,不多说了直接上代码

function varargout = mytest(varargin)
% MYTEST M-file for mytest.fig
% MYTEST, by itself, creates a new MYTEST or raises the existing
% singleton*.
%
% H = MYTEST returns the handle to a new MYTEST or the handle to
% the existing singleton*.
%
% MYTEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYTEST.M with the given input arguments.
%
% MYTEST('Property','Value',...) creates a new MYTEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mytest_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mytest_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 mytest % Last Modified by GUIDE v2.5 17-Feb-2012 15:10:23 % Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mytest_OpeningFcn, ...
'gui_OutputFcn', @mytest_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 mytest is made visible.
function mytest_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 mytest (see VARARGIN) % Choose default command line output for mytest
handles.output = hObject; % Update handles structure
guidata(hObject, handles);
setappdata(handles.myfigure,'is_open',0);
set(handles.myfigure,'menubar','figure','toolbar','figure'); % set(handles.myaxes,'OuterPosition',[0,-30,w/3,h]); % UIWAIT makes mytest wait for user response (see UIRESUME)
% uiwait(handles.myfigure); % --- Outputs from this function are returned to the command line.
function varargout = mytest_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; function myfigure_WindowButtonDownFcn(hObject, eventdata, handles)
% [x,y,but]=ginput(1);
% if(but==1)
% % if x>0&&y>0
% % text(x,y,'q1');
% x1=num2str(x);
% y1=num2str(y);
% s=strcat(x1,',',y1);
% set(handles.mytxt,'String',s);
% % end
% end
is_open=getappdata(handles.myfigure,'is_open');
if is_open==1
p=[0 0 0];
p = get(handles.myaxes,'currentpoint'); A=get(handles.myfigure,'UserData');
r=getappdata(handles.myfigure,'si');
x=num2str(p(1));
y=num2str(p(3));
s=strcat(x,',',y);
set(handles.mytxt,'String',s);
tx=floor(p(3));
ty=floor(p(1));
disp(r.Width)
disp(r.Height)
if tx<=r.Height&&ty<=r.Width&&tx>=1&&ty>=1
r=A(tx,ty,1);
g=A(tx,ty,2);
b=A(tx,ty,3);
rs=strcat(num2str(r),',',num2str(g),',',num2str(b));
set(handles.rgb,'String',rs);
stru=datacon(r,g,b);
set(handles.mystruct,'String',stru);
end
end
% dynpoint(handles.myaxes) ;
% col=get(handles.myaxes,'color');
%
% r=num2str(sum(col));
%
% set(handles.mytxt,'String',r)
function myfigure_WindowButtonUpFcn(hObject, eventdata, handles) % --- Executes when user attempts to close myfigure.
function myfigure_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to myfigure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA) % Hint: delete(hObject) closes the figure
delete(hObject); % --- Executes during object creation, after setting all properties.
function myaxes_CreateFcn(hObject, eventdata, handles)
% hObject handle to myaxes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate myaxes
axis([0 105 0 140]); % --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA) % --------------------------------------------------------------------
function f_open_Callback(hObject, eventdata, handles)
% hObject handle to f_open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
[filename, pathname] = uigetfile( ...
{'*.bmp;*.jpg;*.png;*.jpeg', 'Image Files (*.bmp, *.jpg, *.png,*.jpeg)'; '*.*', 'All Files (*.*)'},'Pick an image');
if isequal(filename,0) || isequal(pathname,0),
return;
end fpath=[pathname filename];
A=imread(fpath);%andles structure with handles and user data (see GUIDATA) r=imfinfo(fpath);
setappdata(handles.myfigure,'si',r);
set(handles.myfigure,'UserData',A);
f=image(A);
setappdata(handles.myfigure,'is_open',1); % --------------------------------------------------------------------
function f_exit_Callback(hObject, eventdata, handles)
% hObject handle to f_exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(findobj('Tag','myfigure'));%关闭主窗口

以上是主程序,其中函数datacon是数据库连接函数

%%%图片像素位置是通过首先取得鼠标在axes中的位置在取整处理后索引颜色的

%%%取点的语句  p = get(handles.myaxes,'currentpoint');

matlab gui matlab gui 鼠标点击显示图像颜色值的更多相关文章

  1. 十. 图形界面(GUI)设计13.鼠标事件

    鼠标事件的事件源往往与容器相关,当鼠标进入容器.离开容器,或者在容器中单击鼠标.拖动鼠标时都会发生鼠标事件.java语言为处理鼠标事件提供两个接口:MouseListener,MouseMotionL ...

  2. 【Unity3D基础】让物体动起来①--UGUI鼠标点击移动

    背景 首先还是先声明自己是比较笨的一个人,总是找不到高效的学习方法,目前自己学习Unity3D的方式主要是两种,一种是直接看高质量的源码,另一种是光看不行还要自己动手,自己写一些有代表性的小程序,这也 ...

  3. (原)python中matplot中获得鼠标点击的位置及显示灰度图像

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6182474.html 参考网址: http://matplotlib.org/examples/pyl ...

  4. html5中canvas的使用 获取鼠标点击页面上某点的RGB

    1.html5中的canvas在IE9中可以跑起来.在IE8则跑不起来,这时候就需要一些东西了. 我推荐这种方法,这样显得代码不乱. <!--[if lt IE9]> <script ...

  5. 工作当中实际运用(3)——js原生实现鼠标点击弹出div层 在点击隐藏

    function onmou(){ var divs=document.getElementById('kefuDV');//获取到你要操作的div if (divs.style.display==& ...

  6. 【Unity3D基础】让物体动起来②--UGUI鼠标点击逐帧移动

    背景 上一篇通过鼠标移动的代码很简单,所以看的人也不多,但是还是要感谢“武装三藏”在博客园给出的评论和支持,希望他也能看到第二篇,其实可以很简单,而且是精灵自控制,关键是代码少是我喜欢的方式,也再次印 ...

  7. 鼠标点击输入框文字消失 value placeholder 以及JQ实现效果 (仿京东的输入框效果)

    鼠标点击输入框文字消失 value实现方法  placeholder实现方法     以及JQ实现placeholder效果 <input type="text" value ...

  8. JS控制鼠标点击事件

    鼠标点击事件就是当鼠标点击元素时,就会出现另一个窗口,类似于百度首页中右上角的“登录”这个按钮,当鼠标点击 登录时,就会出现登录窗口.大体的意思就是这样,直接上代码了,简单易懂. <!DOCTY ...

  9. JQuery怎么实现页面刷新后保留鼠标点击样式的方法

    今天抽空研究了下鼠标点击添加样式的方法.为了防止忘记,写篇文章算是备份吧. $('ul.main-menu li a').each(function(){     if($($(this))[0].h ...

随机推荐

  1. 单身狗福利!利用java实现每天给对象发情话,脱单指日可待!

    引言 最近看到一篇用js代码实现表白的文章,深有感触. 然后发现自己也可以用java代码实现,然后就开始写代码了,发现还挺有意思的,话不多说开搞 实现思路: 使用HttpClient远程获取彩虹屁生成 ...

  2. SpringBoot从入门到精通教程(六)

    之前学了,这么多东西 thyemeaf .MyBatis 还有 配置文件等等,今天我们就来做一个小案例 CRUD,程序员的必备 项目结构 pom.xml <!-- mybatis 相关依赖 -- ...

  3. RocketMQ(七):高性能探秘之MappedFile

    RocketMQ作为消息中间件,经常会被用来和其他消息中间件做比较,比对rabbitmq, kafka... 但个人觉得它一直对标的,都是kafka.因为它们面对的场景往往都是超高并发,超高性能要求的 ...

  4. 【Python 1-8】Python手把手教程之——管理列表List

    遍历列表 在日常开发中,我们经常需要遍历列表的所有元素,对每个元素执行相同的操作.例如,在管理商场的蔬菜时候,需要给所有的蔬菜商品都打7折,并重新生成价格.当我们需要对列表中的每个元素都执行相同的操作 ...

  5. ELK原理介绍

    本篇转载自:https://www.cnblogs.com/aresxin/p/8035137.html 为什么使用日志系统: 日志系统记录了系统运行.业务处理的方方面面,在故障排除.业务分析.数据挖 ...

  6. python初学者-水仙花数简单算法

    输出"水仙花数".所谓水仙花是指一个3位数的十进制数,其各位数字的立方和等于该数本身.例如:153是水仙花数. 用for循环实现水仙花数的计算图如下所示: 1 for i in r ...

  7. 持续提升程序员幸福指数——使用abp vnext设计一款面向微服务的单体架构

    可能你会面临这样一种情况,在架构设计之前,你对业务不甚了解,需求给到的也模棱两可,这个时候你既无法明确到底是要使用单体架构还是使用微服务架构,如果使用单体,后续业务扩展可能带来大量修改,如果使用微服务 ...

  8. 看起来很唬人,然而却简单实用的CAP理论

    在做分布式系统开发时,经常会或多或少的听到CAP理论.或者是处理节点间数据一致性的问题.CAP理论很简单,但却是很多软件设计的宏观指导,因此也有人将之称为架构师必须掌握的理论之一.鉴于理论的东西相对来 ...

  9. offset()与position()的区别

    jQuery中有两个获取元素位置的方法offset()和position(),两者的定义如下: offset(): 获取匹配元素在当前视口的相对偏移. 返回的对象包含两个整形属性:top 和 left ...

  10. 常用的Git命令清单

    目录 名词解释 开卷必读 一. 新建代码库 二.配置 三. 忽略某个文件的改动 四. 增加/删除文件 五. 代码提交 六. 分支 七. 标签 八. 查看信息 九. 远程同步 十. 撤销 十一. Git ...