Pages

Friday, May 15, 2009

Create GIF


用C#制作了一个GIF,有太多色块,颜色Index不好,但我不会调。于是就找到用matlab用制作GIF。
下面是上图的代码
Z = peaks;
surf(Z)
axis tight
set(gca,'nextplot','replacechildren','visible','off')
f = getframe;
[im,map] = rgb2ind(f.cdata,256,'nodither');
im(1,1,1,20) = 0;
for k = 1:20
surf(cos(2*pi*k/20)*Z,Z)
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
end
imwrite(im,map,'DancingPeaks.gif','DelayTime',0,'LoopCount',inf) %g443800

若要从硬盘图像生成GIF,可用下面代码
originIm = imread('C:\0.jpg');
[im,map] = rgb2ind(originIm,256,'dither'); %'dither'失真教少
im(1,1,1,9) = 0;
for k = 1:9
originIm = imread(['C:\' int2str(k) '.jpg']);
im(:,:,1,k) = rgb2ind(originIm,map,'dither');
end
imwrite(im,map,'darling.gif','DelayTime',0.2,'LoopCount',inf) %g443800

BTW:blog中插入图片插入GIF居然不动,把GIF先上传到文件

No comments:

 

Locations of visitors to this page

Web Counters
Cheap Hotel Rates