Matlab在gui中显示动画gif(Matlab display animated gif in gui)

编程入门 行业动态 更新时间:2024-10-25 12:17:44
Matlab在gui中显示动画gif(Matlab display animated gif in gui)

我试图在我的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 end

this 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 end

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,:) )

更多推荐

本文发布于:2023-08-07 02:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动画   gui   Matlab   animated   display

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!