【问题标题】:Pushbutton zoom in and zoom out in GUIGUI中的按钮放大和缩小
【发布时间】:2016-02-10 23:04:05
【问题描述】:

我需要代码来为我的图像按下“放大”、“缩小”按钮。试图使用这个但错误。请帮我。我使用 MATLAB Gui。

function btnZoomIn_Callback(hObject, eventdata, handles)
uicontrol('Style','pushbutton','String','ZoomIn','Units','pixels',...
'Position',[90 10 60 20],'Enable','off',...
'Tag','btnZoomIn','Callback',@btnZoomIn_Callback);
h = guihandles(hObject);
set(h.btnZoomOut,'Enable','on')
data = guidata(hObject);
data.magnif = data.magnif+1;
guidata(hObject, data)

function btnZoomOut_Callback(hObject, eventdata, handles)
uicontrol('Style','pushbutton','String','Zoom Out','Units','pixels',...
'Position',[160 10 60 20],'Enable','off',...
'Tag','btnZoomOut','Callback',@btnZoomOut_Callback);

h = guihandles(hObject);
data = guidata(hObject);
if data.magnif > 1
 data.magnif = data.magnif-1;
  if data.magnif == 1

【问题讨论】:

  • 在您的按钮回调中使用zoom,没有理由尝试重新发明轮子。
  • 另外这段代码也没有什么意义,你是在他们的回调中创建按钮吗?
  • 在大学里,老师给我们布置了缩放按钮的任务。没有人知道该怎么做。我说我不知道​​这个程序。这只是愚蠢的尝试:(
  • 问题是教授自己不知道怎么做程序。他只想要结果。
  • 是俄罗斯教育。我们需要接受它

标签: matlab user-interface matlab-guide


【解决方案1】:

如果你想厚颜无耻(希望这个成语可以翻译......),你可以将你的教授指向内置的缩放按钮。

一个(非 GUIDE)示例:

f = figure;
ax = axes('Parent', f, 'Units', 'Normalized', 'Position', [0.1 0.18 0.8 0.8]);
A = imread('ngc6543a.jpg'); % Read a built-in image as a sample
image(A, 'Parent', ax);

但是,如果您需要一个严肃的答案,请参阅 MATLAB 的 zoom 函数,您可以将其添加到您的按钮回调中。

扩展上面的例子:

f = figure;
ax = axes('Parent', f, 'Units', 'Normalized', 'Position', [0.1 0.18 0.8 0.8]);
A = imread('ngc6543a.jpg'); % Read a built-in image as a sample
image(A, 'Parent', ax);

zoomonbutton = uicontrol('Parent', f, ...
                         'Style', 'pushbutton', ...
                         'Units', 'Normalized', ...
                         'Position', [0.1 0.02 0.4 0.1], ...
                         'String', 'Zoom On', ...
                         'Callback', 'zoom on' ...
                         );

zoomoffbutton = uicontrol('Parent', f, ...
                         'Style', 'pushbutton', ...
                         'Units', 'Normalized', ...
                         'Position', [0.5 0.02 0.4 0.1], ...
                         'String', 'Zoom Off', ...
                         'Callback', 'zoom off' ...
                         );

按下“开启”按钮会打开交互式缩放。来自the documentation

zoom on 打开交互式缩放。当交互式缩放是 在图中启用,在光标位于时按下鼠标按钮 在轴内放大该点或从该点下方的点缩小 鼠。缩放会更改坐标轴范围。使用缩放模式时,您

Zoom in by positioning the mouse cursor where you want the center of the plot to be and either

    Press the mouse button or

    Rotate the mouse scroll wheel away from you (upward).

Zoom out by positioning the mouse cursor where you want the center of the plot to be and either

    Simultaneously press Shift and the mouse button, or

    Rotate the mouse scroll wheel toward you (downward).

按下“关闭”按钮会关闭此交互模式。


希望这可以帮助您朝着正确的方向前进。我建议你研究一下 MATLAB 的文档,它非常全面并且有很多示例。

【讨论】:

  • 哦,谢谢。我希望可以用它来做点什么。
猜你喜欢
  • 2017-12-05
  • 1970-01-01
  • 1970-01-01
  • 2018-05-18
  • 1970-01-01
  • 1970-01-01
  • 2015-11-28
  • 2022-10-17
  • 1970-01-01
相关资源
最近更新 更多