我想创建一个会遍历图像的gui,但是我无法保持GUI的打开状态。它在第一张图片后关闭。
callback
我的代码看起来像那样。我查看了matlab文档示例,在set()
之后他们有了save()
但是这个方法不适用于我,因为我正在更改gui的任何组件。因此,我不确定适用的条件。
我希望gui只在我点击下一个时显示下一个图像。
答案 0 :(得分:2)
与回调处理程序一起,您还应声明一个变量,用于存储当前显示的图像偏移量。您可以使用按钮的UserData属性,而不是将其插入变量。
display = figure('Name','Images');
continue_button = uicontrol('Style','pushbutton','String','Continue','Callback',@ContinueHandler,'UserData',[1 length(images)]);
% When the figure is created, show the first image by default...
imshow(imread(images(1).name));
现在,单击按钮时:
function ContinueHandler(obj,evd)
% retrieve the images data
img_data = obj.UserData;
img_off = img_data(1) + 1;
img_len = img_data(2);
% Retrieve the next image or restart if the last image is being shown...
if (img_off > img_len)
img_nex = 1;
else
img_nex = img_off;
end
% Clear the axes and show the next image...
cla();
imshow(imread(images(img_nex).name));
% Update the images data...
obj.UserData = [img_nex img_len];
end