【基础教程】疫情防护动图制作

   今天元宵节,我也接￶上这￱个平安灯,愿我的国︇家,我的城市,我的家︊人,我的亲人,爱我的人,我爱的人,特︃殊时期,特︉殊祝￱愿,一切都万︃事如意,平︊安度￱过疫情。

   做了一个简单的疫情防护动图,分享一下。

clc

clear

close all

filename='D:\Matlab\Matlab画地图\疫情地图\疫情防治\yiqi.gif';          %输出路径+保存的文件名.gif

path ='D:\Matlab\Matlab画地图\疫情地图\疫情防治\';

Files= dir(strcat(path,'*.png'));%这是要改的文件名的目录,我的是png文件

m=1080;

n=500;

for i=1:length(Files)

    str =Files(i).name;%取出第一个文件的名称

    img = imread(str);     %读取图像;

    img=imresize(img,[m n]) ;

    figure(i)

    imshow(img)

    set(gcf,'color','w');  %设置背景为白色

    set(gca,'units','pixels','Visible','off');

    frame = getframe(gcf);

    im = frame2im(frame);     %将影片动画转换为编址图像,因为图像必须是index索引图像

    imshow(im);

    [I,map] = rgb2ind(im,20); %将真彩色图像转化为索引图像

    if i==1;

        imwrite(I,map,filename,'gif','Loopcount',inf,'DelayTime',0.3);     %Loopcount只是在i==1的时候才有用

    else

        imwrite(I,map,filename,'gif','WriteMode','append','DelayTime',0.3);%DelayTime:帧与帧之间的时间间隔

    end

    pause(0.5)

end

close all

发布了39 篇原创文章 · 获赞 16 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_34763204/article/details/104223750