我试图在我的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 = addingoz.gif&res = landing
谢谢!
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).
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 endthis is my gif image: http://desmond.imageshack.us/Himg822/scaled.php?server=822&filename=loadingoz.gif&res=landing
Thank you!
最满意答案
以下是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,:) )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 endEDIT
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,:) )更多推荐
发布评论