/// <summary> /// 定时获取图片生成 GIF 文件 /// </summary> /// <param name="filename">输出 GIF 文件名</param> /// <param name="getBitmap">获取图片委托</param> /// <param name="width">图片最大高度</param> /// <param name="height">图片最大宽度</param> /// <param name="interval">截屏定时毫秒数</param> /// <param name="maxPixel">最大色彩深度</param> /// <param name="isWaitFinally">释放资源是否等待 GIF 文件处理结束</param> public TimerWriter(string filename, Func <Bitmap> getBitmap, int width, int height, int interval = 40, byte maxPixel = 8, bool isWaitFinally = true) { if (getBitmap == null) { throw new ArgumentNullException(); } if (width <= 0) { throw new IndexOutOfRangeException("width"); } if (height <= 0) { throw new IndexOutOfRangeException("height"); } this.getBitmap = getBitmap; this.maxPixel = (byte)(maxPixel - 2) < 8 ? maxPixel : (byte)8; bitmapQueue = new BitmapInfo.YieldQueue(new BitmapInfo()); gif = new FileWriter(filename, (short)width, (short)height); this.interval = interval < 40 ? 40 : interval; bitmapWait.Set(0); if (this.isWaitFinally = isWaitFinally) { finallyWait.Set(0); } timer = new System.Threading.Timer(onTimer, this, interval, interval); onTimer(null); AutoCSer.Threading.ThreadPool.TinyBackground.Start(write); }