[英]matlab uicontrols
我做了一个gui,我有一个代码(感谢Amro)向我展示了一个gif文件。
我想在“ hAxes”中显示此gif文件,直到gui关闭(与其他uicontrol一起显示)。
我有一个包含200张图片(image1.jpg,image2.jpg ... image200.jpg)的文件夹,并且我执行了有关这些图片的一些操作(在loading1 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]);
%%这是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显示了hAxes(gif文件工作正常),但是gui没有显示loading1 uicontrol。 我要他同时显示(hAxes和loading1)
所以我的意思是我要让gui向我展示gif文件和'loading1'uicontrol。 我认为'loading1'无法正常工作,因为显示gif文件的代码中的'while'。
这就是我得到的:
这就是我想要得到的:
接着:
接着:
等等...
我认为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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.