簡體   English   中英

Matlab UIControls

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM