Matlab在gui中显示动画gif [英] Matlab display animated gif in gui
问题描述
我正在尝试在GUI中显示GIF图像,但它不起作用.它向我显示了一个伪造的图像(不是GIF,并且具有不同的颜色).
I am trying to display a GIF image in my GUI, and it doesn't work. It displays me a fake image (not a GIF, and with different colors).
我知道文件交换中有一个动画GIF",但我更喜欢其他东西:/
我尝试了下一个代码,但是不起作用:
I know there is an "Animated GIF" in File Exchange but I prefer something else :/
I tried the next code, but it doesn't work:
function [] = GUI_400()
hFig = figure('Name','Simulation Plot Window','Menubar','none', 'Resize','off', 'WindowStyle','modal', 'Position',[300 300 1150 600]);
movegui(hFig, 'center');
hAxes = axes('Parent',hFig,'Units','pixels','Position',[362 242 424 359]); %# so the position is easy to define
image(imread('loading.gif', 'gif'),'Parent',hAxes); %# Plot the image
set(hAxes,'Visible','off', 'handlevisibility', 'off'); %# Turn the axes visibility off
end
这是我的gif图片: http://desmond.imageshack.us /Himg822/scaled.php?server=822&filename=loadingoz.gif&res=着陆
this is my gif image: http://desmond.imageshack.us/Himg822/scaled.php?server=822&filename=loadingoz.gif&res=landing
谢谢!
推荐答案
以下是GIF播放器的示例:
Here is an example of a GIF player:
function gifPlayerGUI(fname)
%# 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);
%# prepare GUI, and show first frame
hFig = figure('Menubar','none', 'Resize','off', ...
'Units','pixels', 'Position',[300 300 imgW imgH]);
movegui(hFig,'center')
hAx = axes('Parent',hFig, ...
'Units','pixels', 'Position',[1 1 imgW imgH]);
hImg = imshow(img(:,:,:,1), map, 'Parent',hAx);
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))
%# pause for the specified delay
pause(delay)
end
end
编辑
正如我在评论中提到的那样,您发布的示例GIF图像非常奇怪.这是使其生效的更改.在while循环内,在set(hImg,'CData',..)
行之后立即添加以下内容:
EDIT
As I mentioned in the comments, the sample GIF image you posted is rather strange. Here are the changes to make it work. Inside the while loop, add the following immediately after the set(hImg,'CData',..)
line:
%# update colormap
n = max(max( img(:,:,:,counter) ));
colormap( info(counter).ColorTable(1:n,:) )
这篇关于Matlab在gui中显示动画gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!