由一些图片生成gif的MATLAB代码

如题。
代码如下:

stepall=60;
for i=1:stepall
    picname=[num2str(i) '.jpg'];
    im = imread(picname);
%     set(gcf,'outerposition',get(0,'screensize'));% matlab窗口最大化
%     frame=getframe(gcf);  
%     im=frame2im(frame);%制作gif文件,图像必须是index索引图像  
    [I,map]=rgb2ind(im,20);          
    if i==1
        imwrite(I,map,'NameOfYourGifFile.gif','gif', 'Loopcount',inf,'DelayTime',0.2);%第一次必须创建!
    elseif i==stepall+1
        imwrite(I,map,'NameOfYourGifFile.gif','gif','WriteMode','append','DelayTime',0.2);
    else
        imwrite(I,map,'NameOfYourGifFile.gif','gif','WriteMode','append','DelayTime',0.2);
    end  
    close all
end

猜你喜欢

转载自blog.csdn.net/weixin_44306064/article/details/88647733