资源简介
c# 使用图片制作 gif 的时候,需要用到一个类,那就是 AnimatedGifEncoder,使用的时候,把这个类复制进工程中,就可以使用相关类了。
代码片段和文件信息
using System;
using System.Collections;
using System.Drawing;
using System.IO;
namespace 你自己的命名空间
{
//我使用的是 vs2017 .net framework 4.0
internal class AnimatedGifEncoder
{
protected int width; // image size
protected int height;
protected Color transparent = Color.Empty; // transparent color if given
protected int transIndex; // transparent index in color table
protected int repeat = -1; // no repeat
protected int delay = 0; // frame delay (hundredths)
protected bool started = false; // ready to output frames
// protected BinaryWriter bw;
protected FileStream fs;
protected Image image; // current frame
protected byte[] pixels; // BGR byte array from frame
protected byte[] indexedPixels; // converted frame indexed to palette
protected int colorDepth; // number of bit planes
protected byte[] colorTab; // RGB palette
protected bool[] usedEntry = new bool[256]; // active palette entries
protected int palSize = 7; // color table size (bits-1)
protected int dispose = -1; // disposal code (-1 = use default)
protected bool closeStream = false; // close stream when finished
protected bool firstframe = true;
protected bool sizeSet = false; // if false get size from first frame
protected int sample = 10; // default sample interval for quantizer
/**
* Sets the delay time between each frame or changes it
* for subsequent frames (applies to last frame added).
*
* @param ms int delay time in milliseconds
*/
public void SetDelay(int ms)
{
delay = (int)System.Math.Round(ms / 10.0f);
}
/**
* Sets the GIF frame disposal code for the last added frame
* and any subsequent frames. Default is 0 if no transparent
* color has been set otherwise 2.
* @param code int disposal code.
*/
public void SetDispose(int code)
{
if (code >= 0)
{
dispose = code;
}
}
/**
* Sets the number of times the set of GIF frames
* should be played. Default is 1; 0 means play
* indefinitely. Must be invoked before the first
* image is added.
*
* @param iter int number of iterations.
* @return
*/
public void SetRepeat(int iter)
{
if (iter >= 0)
{
repeat = iter;
}
}
/**
* Sets the transparent color for the last added frame
* and any subsequent frames.
* Since all colors are subject to modification
* in the quantization process the color in the final
* palette for each fram
- 上一篇:通讯录模板
- 下一篇:C# u盘操作源代码
相关资源
- C# u盘操作源代码
- C# ECHART WPF 开发,非常漂亮的demo
- modbus协议的上位机
- 旅行商问题 遗传算法 贪婪基因重组
- C#利用fft实现快速卷积
- C# 矩阵运算实数+复数
- Winform分页控件(C#)
- 用VS2010做的绘图板C#
- c#实现拓扑关系图
- 深入.net平台和C#编程课后练习答案
- c# 进程外Com服务exe编写和调用
- 利用C#实现卷积运算
- C#开发IE插件(ActiveX)
- c# winform RichTextBox Autocomplete 自动完成
- C#编程(纹理映射 OPENGL)
- C#.net4.0 采用多线程 基于Socket的聊天室
- 蚁群算法c#编程实现
- C#实现GPS时间的计算GPS周和秒
- C#图片转视频源码
- C#实现CAD绘图功能
- 基于C#的GPS数据采集源码
- 数字信号处理中C#语言求卷积
- C#项目管理系统
- 一个开源的C#蜘蛛爬虫程序,看了让你
- C# 论文:实验室设备管理系统+数据库
- C#中的DataGrid数据绑定代码
- c#版的SIFT算法
- C# 贪吃蛇游戏 绝对简单易懂
- C# Neo4jDriver操作Neo4j图形数据库底层代
- c# winform 多语言切换 本地化
评论
共有 条评论