LaTex+beamer+animate中批处理加载图像文件的方法

17 篇文章 0 订阅
10 篇文章 0 订阅

想做一个动画,这个动画有40幅图片构成,文件名是规范命名的,如:

moviefile1.jpg,moviefile2.jpg,...,moviefile40.jpg.一个一个第手工添加肯定会累死.

下面的代码定义了计数器和字符串变量,实现了批处理加载图像文件的方法,并演示了$MATLAB$中的动画功能,有点类似gif动画文件:

%%============================================
\begin{frame}[fragile]
	\frametitle{动画的小例子$plot5$}
	\framesubtitle{~$MATLAB$~简单的示例}
	\begin{columns}
		\column{0.425\textwidth}<1->

\begin{center}
\tiny
\begin{lstlisting}[language=Matlab,numberstyle=\tiny,	xleftmargin=1em,xrightmargin=0em, aboveskip=1em ]
%% 动画
maxj=40;
Z = peaks(maxj);
figure('Renderer','zbuffer');
surf(Z);
axis tight manual;
set(gca,'NextPlot','replaceChildren');
for j = 1:maxj
surf(sin(2*pi*j/maxj)*Z,Z)
F(j) = getframe;
fn=['moviefile',num2str(j),'.jpg'];
saveas(gcf,fn)
end
movie(F,2) % Play the movie 2 times
\end{lstlisting}
\end{center}

	\column{0.575\textwidth}<1->
		
\setcounter{thirdcounter}{0}%设置计数器的值,每次增加一个值用 
\begin{animateinline}[autoplay, loop,   
	begin={\begin{tikzpicture}[scale=1]    
		\useasboundingbox (-1cm,0cm) rectangle(5cm,6cm);},    
	end={\end{tikzpicture}}]{10}  
	%总共生成40帧画面,以每秒10帧的速度自动播放    
	\multiframe{40}{Inum=0+1}{%  
		%Inum:每帧
		\stepcounter{thirdcounter}
		\def\abc{moviefile\thethirdcounter} %定义动态字符串作为文件名
		\node[draw] at (2,3){\includegraphics[width=0.925\textwidth,totalheight=0.725\textheight]{\abc}};  
	}%    
\end{animateinline}   

	\end{columns}
	
\end{frame}
最终的效果如下:


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值