private void LoadThumbnail(OperatorPreset preset, bool useCache = true) { var imagePath = preset.BuildImagePath(); if (useCache && _cache.ContainsKey(imagePath)) { XImage.Source = _cache[imagePath]; return; } if (File.Exists(imagePath)) { var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(imagePath, UriKind.RelativeOrAbsolute); //bitmap.CacheOption = BitmapCacheOption.OnLoad; //bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache; bitmap.EndInit(); bitmap.Freeze(); XImage.Source = bitmap; _cache[imagePath] = bitmap; } else { XImage.Source = null; Logger.Info("Failed to load thumbnail {0}", imagePath); _cache[imagePath] = null; } }
public void RenderAndSaveThumbnail(OperatorPreset preset) { var op = App.Current.MainWindow.XParameterView.ShownOperator; // todo: remove access to parameter view! if (op == null || !op.Outputs.Any()) { return; } var output = op.Outputs.First(); if (LivePreviewEnabled) { if (App.Current.MainWindow.XRenderView.Operator != null && App.Current.MainWindow.XRenderView.Operator.Outputs.Any()) { output = App.Current.MainWindow.XRenderView.Operator.Outputs[0]; } } var currentTime = App.Current.Model.GlobalTime; var filePath = preset.BuildImagePath(); var result = Regex.Match(filePath, @"(.*)/(.*)\.png"); if (result == null) { throw new Exception("Invalid filepath format for thumbnails:" + filePath); } var directory = result.Groups[1].Value; var filename = result.Groups[2].Value; using (var sequenceCreator = new SequenceCreator()) { sequenceCreator.Setup(output, height: THUMB_HEIGHT, width: THUMB_WIDTH, startTime: currentTime, endTime: currentTime, frameRate: 10000, fileExtension: "png", skipExistingFiles: false, directory: directory, filenameFormat: filename); sequenceCreator.RenderFrame(); } }