C#制作gif
2016-12-04 17:32
323 查看
用到的库
emgucvGif.Components(是一个dll文件,需要自己添加到
reference中)
说明
实现的功能:将一幅图片由小到大旋转输出,可以设置背景图片这个功能主要是自己不想复习的时候做着玩的。。。其实没啥用(premiere几分钟就能做出相同的效果)
代码
string inputFn = "./img/1.jpg"; string outputFn = "./img/test.gif"; string bkgFn = "./img/2.jpg"; int interval = 50; int number = 60; Image<Bgr, Byte> emg = new Image<Bgr, byte>(inputFn); emg = emg.Resize( 0.5, Emgu.CV.CvEnum.Inter.Nearest); Bitmap img; AnimatedGifEncoder gif = new AnimatedGifEncoder(); gif.SetDelay(interval); gif.Start(outputFn); gif.SetRepeat(0); //gif.SetTransparent(Color.Green); gif.SetSize(emg.Width, emg.Height); Image<Bgr, Byte> bkgImg = new Image<Bgr, byte>(bkgFn); for(int i=0;i<number;i++) { Image<Bgr, Byte> tmp = emg.Resize(1.0 * (i + number/2) / (number + number/2), Emgu.CV.CvEnum.Inter.Nearest); Image<Bgr, Byte> con = bkgImg.Resize(emg.Width, emg.Height, Inter.Nearest); //new Image<Bgr, byte>(emg.Width, emg.Height, new Bgr(0,255, 255)); tmp = tmp.Rotate(360/number * i, new PointF(tmp.Width/2, tmp.Height/2), Inter.Cubic, new Bgr(0,0,0), true); for (int m = (emg.Height - tmp.Height) / 2; m < (emg.Height - tmp.Height) / 2 + tmp.Height;m++ ) { for (int n = (emg.Width - tmp.Width) / 2; n < (emg.Width - tmp.Width) / 2 + tmp.Width; n++) { con.Data[m, n, 0] = tmp.Data[m - (emg.Height - tmp.Height) / 2, n - (emg.Width - tmp.Width) / 2, 0]; con.Data[m, n, 1] = tmp.Data[m - (emg.Height - tmp.Height) / 2, n - (emg.Width - tmp.Width) / 2, 1]; con.Data[m, n, 2] = tmp.Data[m - (emg.Height - tmp.Height) / 2, n - (emg.Width - tmp.Width) / 2, 2]; } } img = con.ToBitmap(); //img.MakeTransparent(); img.Save("./img/" + i + ".bmp"); gif.AddFrame(img); } gif.Finish();
相关文章推荐
- c# 怎样实现用几张图片制作 gif?怎样对图片像素值进行修改?上代码
- C#制作透明色GIF动画的类
- 用c#和wpf制作屏幕录像gif工具
- 使用c#制作的一个树形下拉控件
- 转贴 使用C#制作《邮件特快专递》
- Visaul C#托盘程序制作心得
- Visaul C#托盘程序制作心得
- 使用C#制作《邮件特快专递》
- 用C#.net轻松制作不规则窗体(附源码)
- 在C#中轻松制作仿OutLook的界面
- 用C#制作PDF文件全攻略
- 使用C#制作的更换桌面背景程序
- 用C#制作PDF文件全攻略
- [C#]在网页中动态的生成一个gif图片
- 利用C#制作一个仿IE地址栏的文本框
- 用NAnt编译带有资源文件(*.resx,*.bmp,*.gif等)的C#项目
- 手把手教你C#项目制作安装程序
- [原创]使用C#制作《邮件特快专递》
- 使用c#制作的一个树形下拉控件
- 利用C#制作一个仿IE地址栏的文本框