简体   繁体   English

Matlab UIControls

[英]matlab uicontrols

I made a gui and I have a code (thanks Amro) that shows me a gif file. 我做了一个gui,我有一个代码(感谢Amro)向我展示了一个gif文件。

I want to show this gif file in 'hAxes' till the gui is closed (show it with the other uicontrol). 我想在“ hAxes”中显示此gif文件,直到gui关闭(与其他uicontrol一起显示)。

I have a folder that has 200 pictures (image1.jpg, image2.jpg... image200.jpg) and I perform some things about these images (in loading1 uicontrol). 我有一个包含200张图片(image1.jpg,image2.jpg ... image200.jpg)的文件夹,并且我执行了有关这些图片的一些操作(在loading1 uicontrol中)。

I try something like: 我尝试类似的东西:

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]);                 

%% this is what Amro made to show the gif file %%这是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

%% and this is the rest of my code: %%,这是我的其余代码:

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

but this code doesn't work: in this code, the gui shows the hAxes (the gif file works good), but the gui doesn't show the loading1 uicontrol. 但是这段代码不起作用:在这段代码中,gui显示了hAxes(gif文件工作正常),但是gui没有显示loading1 uicontrol。 I want him to show both (hAxes and loading1) 我要他同时显示(hAxes和loading1)

so I mean that I want the gui to show me the gif file and 'loading1' uicontrol both. 所以我的意思是我要让gui向我展示gif文件和'loading1'uicontrol。 I think that the 'loading1' is not working because of the 'while' in the code that shows the gif file. 我认为'loading1'无法正常工作,因为显示gif文件的代码中的'while'。

this is what I got: 这就是我得到的:

在此处输入图片说明

and this is what I want to get: 这就是我想要得到的:

在此处输入图片说明

and then: 接着:

在此处输入图片说明

and then: 接着:

在此处输入图片说明

etc... 等等...

I think that the uicontrol does not appear because it is called after the continuous loop that handle the gif image and therefore only at the moment that you close your figure. 我认为uicontrol不会出现,因为它是在处理gif图像的连续循环之后调用的,因此仅在关闭图形时才调用。

Using your code and creating the uicontrol before the loop, it seems to work as you expect it to. 使用您的代码并在循环之前创建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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM