使用gif的MATLAB动画闪屏

时间:2016-05-23 00:00:06

标签: matlab

我正在创建一个MATLAB可执行应用程序。在MATLAB中创建可执行文件时,它们会为您提供添加启动画面的选项。我用普通图像,png和jpg尝试了这个。但我想使用动画图像,如加载GIF图像。因为我的程序需要一段时间来编译和执行,所以我希望用户知道它正在加载,因此它们不会完全退出。我试图将gif图像添加到我的启动画面,但它没有用。它只显示了一幅静止图像。有没有办法在我的可执行MATLAB应用程序中添加动画启动画面或gif。

1 个答案:

答案 0 :(得分:0)

我认为你不能。但是你可以做的是在窗口中显示GIF并每x秒更新一次帧。这是一个例子

% Read in your GIF file. Don't forget to read in the colour map as it is
% required for display.
[I, map]=imread('http://i.imgur.com/K9CLvNm.gif','Frames','all');

% Create a figure to hold your splashscreen
hfig=figure;
set(hfig,'Menubar', 'none');
set(hfig,'name','Please wait. Loading...','numbertitle','off');

% Set a timer to dynamically update the plot every 0.1 sec
t=timer('TimerFcn', {@timerCallbackFcn, hfig, I, map},'ExecutionMode','FixedRate','Period',0.1);

% Start the timer
start(t);

% Do your stuff here
for j=1:10
    pause(1);
end

% Clean-up
stop(t);
delete(t);
delete(hfig);

然后在名为timerCallbackFcn.m

的文件中创建计时器更新功能
% This is the timer function to update the figure. 
% Save as timerCallbackFcn.m
function timerCallbackFcn(hTimer, eventData, hfig, I, map)
    figure(hfig);

    % i is the frame index
    persistent i;    
    if isempty(i), i=1; end

    % display the i-th frame in the GIF
    imshow(I(:,:,i),map);    

    % increment frame index i
    i=i+1;
    numframes=size(I,4);
    if (i>numframes), i=1; end
end
相关问题