public ScreenRecorder(int fps, float durationSeconds, Rectangle captureRectangle, string cachePath, ScreenRecordOutput outputType) { if (string.IsNullOrEmpty(cachePath)) { throw new Exception("Screen recorder cache path is empty."); } FPS = fps; DurationSeconds = durationSeconds; CaptureRectangle = captureRectangle; CachePath = cachePath; OutputType = outputType; if (OutputType == ScreenRecordOutput.AVI || OutputType == ScreenRecordOutput.AVICommandLine) { bool showOptions = OutputType == ScreenRecordOutput.AVI; aviCache = new AVICache(CachePath, FPS, CaptureRectangle.Size, showOptions); } else if (OutputType == ScreenRecordOutput.GIF) { hdCache = new HardDiskCache(CachePath); } }
public void SaveAsGIF(string path, GIFQuality quality) { if (imgCache != null && imgCache is HardDiskCache && !IsRecording) { HardDiskCache hdCache = imgCache as HardDiskCache; using (AnimatedGifCreator gifEncoder = new AnimatedGifCreator(path, delay)) { int i = 0; int count = hdCache.Count; foreach (Image img in hdCache.GetImageEnumerator()) { i++; OnEncodingProgressChanged((int)((float)i / count * 100)); using (img) { gifEncoder.AddFrame(img, quality); } } } } }