/// <summary> /// Creates a visual for the xps document. /// </summary> /// <param name="sourceFile">Source file.</param> /// <param name="visualSize">Reference to export dimensions of the visual.</param> /// <returns>Visual of the file.</returns> private Visual CreateXpsVisual(string sourceFile, out IntSize visualSize) { try { XpsDocument xpsDocument = new XpsDocument(sourceFile, FileAccess.Read); FixedDocumentSequence documentPageSequence = xpsDocument.GetFixedDocumentSequence(); DocumentPage documentPage = documentPageSequence.DocumentPaginator.GetPage(0); visualSize.Width = (int)documentPage.Size.Width; visualSize.Height = (int)documentPage.Size.Height; xpsDocument.Close(); return documentPage.Visual; } catch { throw new Exception(); } }
/// <summary> /// Creates a visual from screencaptures. /// </summary> /// <param name="sourceFile">Source file.</param> /// <param name="timeSpan">Time span where the capture has to be done.</param> /// <param name="visualSize">Reference to export dimensions of the visual.</param> /// <returns>Visual of the file.</returns> private Visual CreateVideoVisual(string sourceFile, TimeSpan timeSpan, out IntSize visualSize) { try { Uri sourceUri = new Uri(sourceFile); var mutexLock = new Mutex(false, sourceUri.GetHashCode().ToString()); mutexLock.WaitOne(); MediaPlayer mediaPayer = new MediaPlayer { Volume = 0, ScrubbingEnabled = true }; mediaPayer.Open(sourceUri); mediaPayer.Pause(); mediaPayer.Position = timeSpan; Thread.Sleep(1000); visualSize.Width = mediaPayer.NaturalVideoWidth; visualSize.Height = mediaPayer.NaturalVideoHeight; DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { drawingContext.DrawVideo(mediaPayer, new Rect(0, 0, visualSize.Width, visualSize.Height)); } mediaPayer.Close(); mutexLock.ReleaseMutex(); return drawingVisual; } catch { throw new Exception(); } }