【问题标题】:matlab uicontrolsmatlab ui控件
【发布时间】:2012-06-18 09:28:47
【问题描述】:

我制作了一个 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”。

这是我得到的:

这就是我想要得到的:

然后:

然后:

等等……

【问题讨论】:

    标签: matlab user-interface set figure uicontrol


    【解决方案1】:

    我认为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 文本,这就是这段代码在我的计算机上所做的。您还希望它运行哪些其他代码?请相应地更新您的问题。
    • 代码太长了,我只放相关代码。我现在正努力在我的主题中解释更多。
    猜你喜欢
    • 1970-01-01
    • 2012-04-04
    • 2011-11-23
    • 2012-04-29
    • 2020-11-26
    • 1970-01-01
    • 2011-03-30
    • 2013-12-28
    • 1970-01-01
    相关资源
    最近更新 更多