matlab uicontrols
我制作了一个gui,我有一个代码(谢谢Amro),可以显示一个gif文件 我想在“hAxes”中显示此gif文件,直到gui关闭(用另一个uicontrol显示) 我有一个有200张图片的文件夹(image1.jpg,image2.jpg…image200.jpg),我对这些图片执行一些操作(在加载1 uicontrol中) 我试着做如下事情:matlab uicontrols,matlab,user-interface,set,figure,uicontrol,Matlab,User Interface,Set,Figure,Uicontrol,我制作了一个gui,我有一个代码(谢谢Amro),可以显示一个gif文件 我想在“hAxes”中显示此gif文件,直到gui关闭(用另一个uicontrol显示) 我有一个有200张图片的文件夹(image1.jpg,image2.jpg…image200.jpg),我对这些图片执行一些操作(在加载1 uicontrol中) 我试着做如下事情: hFigure = figure('units','pixels','position',[300 300 424 470],'menubar','no
hFigure = figure('units','pixels','position',[300 300 424 470],'menubar','none',...
'name','start processing','numbertitle','off','resize','off');
hAxes = axes('Parent',hFigure,'Units','pixels','Position',[0 112 424 359]);
%%这是Amro用来显示gif文件的内容
fname = 'loading.gif';
%# read all GIF frames**
info = imfinfo(fname, 'gif');
delay = ( info(1).DelayTime ) / 100;
[img,map] = imread(fname, 'gif', 'frames','all');
[imgH,imgW,~,numFrames] = size(img);
hImg = imshow(img(:,:,:,1), map, 'Parent',hAxes);
pause(delay)
%# loop over frames continuously
counter = 1;
while ishandle(hImg)
%# increment counter circularly
counter = rem(counter, numFrames) + 1;
%# update frame
set(hImg, 'CData',img(:,:,:,counter))
%# update colormap
n = max(max( img(:,:,:,counter) ));
colormap( info(counter).ColorTable(1:n,:) )
%# pause for the specified delay
pause(delay)
end
%%这是我代码的其余部分:
set(hAxes,'Visible','off', 'handlevisibility', 'off');
%% loading1 shows a data
loading1 = uicontrol('style','text','unit','pix','position',[0 72 424 40],...
'backgroundcolor','r','fontsize',20);
for i=1:200
image = horzcat('now processing ', 'image', num2str(i), '.jpg of 200 images')
set(loading1,'string',image);
drawnow;
end
但该代码不起作用:在该代码中,gui显示HAX(gif文件工作正常),但gui不显示加载1 uicontrol。我想让他同时展示(hAxes和loading1)
因此,我的意思是,我希望gui同时显示gif文件和“加载1”uicontrol。
我认为“加载1”不起作用,因为显示gif文件的代码中有“while”
这就是我得到的:
set(hAxes,'Visible','off', 'handlevisibility', 'off');
%% loading1 shows a data
loading1 = uicontrol('style','text','unit','pix','position',[0 72 424 40],...
'backgroundcolor','r','fontsize',20);
for i=1:200
image = horzcat('now processing ', 'image', num2str(i), '.jpg of 200 images')
set(loading1,'string',image);
drawnow;
end
这就是我想要的:
set(hAxes,'Visible','off', 'handlevisibility', 'off');
%% loading1 shows a data
loading1 = uicontrol('style','text','unit','pix','position',[0 72 424 40],...
'backgroundcolor','r','fontsize',20);
for i=1:200
image = horzcat('now processing ', 'image', num2str(i), '.jpg of 200 images')
set(loading1,'string',image);
drawnow;
end
然后:
然后:
等等。我认为,
uicontrol
不会出现,因为它是在处理gif图像的连续循环之后调用的,因此仅在您关闭图形的那一刻调用
使用您的代码并在循环之前创建uicontrol
,它似乎按照您的预期工作
hFigure=figure('units','pixels',...
'position',[300 300 424 470],...
'menubar','none',...
'name','start processing',...
'numbertitle','off',...
'resize','off');
hAxes=axes('Parent',hFigure,...
'Units','pixels',...
'Position',[0 112 424 359]);
% loading1 shows a data
loading1=uicontrol('parent',hFigure,...
'style','text',...
'unit','pix',...
'position',[0 72 424 40],...
'backgroundcolor','r',...
'fontsize',20);
set(loading1,'string','now loading file 1 of 3');
filename='gif.gif';
% read all GIF frames
info=imfinfo(filename,'gif');
delay=(info(1).DelayTime)/100;
[img map]=imread(filename,'gif','frames','all');
[imgH imgW void numFrames]=size(img);
hImg=imshow(img(:,:,:,1),map,'Parent',hAxes);
pause(delay);
% loop over frames continuously
counter=1;
while(ishandle(hImg))
% increment counter circularly
counter=rem(counter,numFrames)+1;
% update frame
set(hImg,'CData',img(:,:,:,counter));
% update colormap
n=max(max(img(:,:,:,counter)));
colormap(info(counter).ColorTable(1:n,:));
% pause for the specified delay
pause(delay);
end
我认为,
uicontrol
不会出现,因为它是在处理gif图像的连续循环之后调用的,因此仅在您关闭图形时调用
使用您的代码并在循环之前创建uicontrol
,它似乎按照您的预期工作
hFigure=figure('units','pixels',...
'position',[300 300 424 470],...
'menubar','none',...
'name','start processing',...
'numbertitle','off',...
'resize','off');
hAxes=axes('Parent',hFigure,...
'Units','pixels',...
'Position',[0 112 424 359]);
% loading1 shows a data
loading1=uicontrol('parent',hFigure,...
'style','text',...
'unit','pix',...
'position',[0 72 424 40],...
'backgroundcolor','r',...
'fontsize',20);
set(loading1,'string','now loading file 1 of 3');
filename='gif.gif';
% read all GIF frames
info=imfinfo(filename,'gif');
delay=(info(1).DelayTime)/100;
[img map]=imread(filename,'gif','frames','all');
[imgH imgW void numFrames]=size(img);
hImg=imshow(img(:,:,:,1),map,'Parent',hAxes);
pause(delay);
% loop over frames continuously
counter=1;
while(ishandle(hImg))
% increment counter circularly
counter=rem(counter,numFrames)+1;
% update frame
set(hImg,'CData',img(:,:,:,counter));
% update colormap
n=max(max(img(:,:,:,counter)));
colormap(info(counter).ColorTable(1:n,:));
% pause for the specified delay
pause(delay);
end
谢谢你的评论。我试过你的建议,但没用。我认为它不起作用,因为它进入无限循环。按照您的建议,它显示了另一个uicontrol,但在while(ishandle(hImg))循环后不运行代码…什么不工作?您在问题中提到,您希望GUI显示gif图像和uicontrol文本,这就是此代码在我的计算机上的作用。您希望它运行什么其他代码?请相应地更新你的问题。代码太长了,所以我只放了相关的代码。我现在正努力在我的主题中解释更多。谢谢你的评论。我试过你的建议,但没用。我认为它不起作用,因为它进入无限循环。按照您的建议,它显示了另一个uicontrol,但在while(ishandle(hImg))循环后不运行代码…什么不工作?您在问题中提到,您希望GUI显示gif图像和uicontrol文本,这就是此代码在我的计算机上的作用。您希望它运行什么其他代码?请相应地更新你的问题。代码太长了,所以我只放了相关的代码。我现在正努力在我的主题中解释更多。