Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab在gui中显示动画gif_Matlab_User Interface_Gif - Fatal编程技术网

Matlab在gui中显示动画gif

Matlab在gui中显示动画gif,matlab,user-interface,gif,Matlab,User Interface,Gif,我试图在GUI中显示GIF图像,但它不起作用。它给我显示了一个假图像(不是GIF,而且颜色不同) 我知道在文件交换中有一个“动画GIF”,但我更喜欢别的东西:// 我尝试了下一个代码,但不起作用: function [] = GUI_400() hFig = figure('Name','Simulation Plot Window','Menubar','none', 'Resize','off', 'WindowStyle','modal', 'Position',[300 30

我试图在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图像:


谢谢大家!

下面是一个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循环中,在
集合(hImg,'CData',..)之后立即添加以下内容
行:

%# update colormap
n = max(max( img(:,:,:,counter) ));
colormap( info(counter).ColorTable(1:n,:) )

以下是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循环中,在
集合(hImg,'CData',..)之后立即添加以下内容
行:

%# update colormap
n = max(max( img(:,:,:,counter) ));
colormap( info(counter).ColorTable(1:n,:) )

我建议您这样显示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])

我建议您这样显示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])

我试图在其他图像上检查此代码,但不起作用:/1第一帧很好,但下三帧不行,5帧很好,6-8帧不行,等等。。(坏帧变黑了,虽然是白色的)。我把我的gif图像放在我的主题中。谢谢。@AlonShmiel:你能把有问题的文件上传到某个地方,让我测试一下吗?可能是透明度的问题。@AlonShmiel:起初我怀疑你的样本图像被破坏了,但现在我想我知道问题出在哪里了;GIF中的每个帧(索引图像)使用不同的颜色贴图。显然,IMREAD将只返回第一帧的颜色映射。谢天谢地,我们可以从IMFINFO
info(idx).ColorTable
获得每帧的正确cmap。即使这样,cmap也需要在相应图像中存在的最大索引处进行裁剪。我将编辑我的答案,向您展示您需要进行的更改,以使其与您的图像一起工作…现在它可以工作了!衷心感谢你。(以后,我将尝试创建一个好的gif,对不起)。我尝试在其他图像上检查此代码,但它不起作用:/第一帧是好的,但下三帧不是,第五帧是好的,第6-8帧不是,等等。。(坏帧变黑了,虽然是白色的)。我把我的gif图像放在我的主题中。谢谢。@AlonShmiel:你能把有问题的文件上传到某个地方,让我测试一下吗?可能是透明度的问题。@AlonShmiel:起初我怀疑你的样本图像被破坏了,但现在我想我知道问题出在哪里了;GIF中的每个帧(索引图像)使用不同的颜色贴图。显然,IMREAD将只返回第一帧的颜色映射。谢天谢地,我们可以从IMFINFO
info(idx).ColorTable
获得每帧的正确cmap。即使这样,cmap也需要在相应图像中存在的最大索引处进行裁剪。我将编辑我的答案,向您展示您需要进行的更改,以使其与您的图像一起工作…现在它可以工作了!衷心感谢你。(在未来,我将尝试创建一个好的gif,对不起)。