我正在尝试在GUI中显示GIF图像,但它不起作用。它向我显示一个假图像(不是GIF,并且有不同的颜色)。
我知道文件交换中有一个“动画GIF”,但我更喜欢别的东西:/
我尝试了下一个代码,但它不起作用:
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=landing
谢谢!
答案 0 :(得分:4)
以下是GIF播放器的示例:
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',..)
行后立即添加以下内容:
%# update colormap
n = max(max( img(:,:,:,counter) ));
colormap( info(counter).ColorTable(1:n,:) )
答案 1 :(得分:0)
我建议像这样显示你的gif。这样,你就没有讨厌的while循环阻塞回调和其他代码执行。
jLabel = javaObjectEDT('javax.swing.JLabel',javaObjectEDT('javax.swing.ImageIcon',which([fname '.gif'])));
[hJ,hC] = javacomponent(jLabel,getpixelposition(hFig).*[0 0 1 1],hFig);
set(hC,'units','normalized','position',[0 0 1 1])