/// <summary> /// Prints the card layout to the default printer /// </summary> private void btnPrint_Click(object sender, RoutedEventArgs e) { PrintLayout layout = new PrintLayout(); double videoWidth = CameraVideoDeviceControl.ActualWidth * WebcamDevice.thisDpiWidthFactor; double videoHeight = CameraVideoDeviceControl.ActualHeight * WebcamDevice.thisDpiHeightFactor; double imageWidth = layout.ImageToPrint.Width; double imageHeight = layout.ImageToPrint.Height; double widthRatio = videoWidth / imageWidth; double heightRatio = videoHeight / imageHeight; PrintDialog printDialog = new PrintDialog(); // Set image and adjust to new size layout.ImageToPrint.Source = OutputImage.Source; // Add face markers if (RecognizedFaces != null && RecognizedFaces.Length > 0) { int index = 0; foreach (var face in RecognizedFaces) { // Draw rectangles around faces FaceMarker fm = new FaceMarker(face.Attributes.Age.ToString(), face.Attributes.Gender); fm.Height = Math.Round(face.FaceRectangle.Height / heightRatio); fm.Width = Math.Round(face.FaceRectangle.Width / widthRatio); layout.FaceCanvas.Children.Add(fm); fm.HairlineColor = brushList[index]; Canvas.SetZIndex(fm, 1); Canvas.SetTop(fm, Math.Round(face.FaceRectangle.Top / heightRatio)); Canvas.SetLeft(fm, Math.Round(face.FaceRectangle.Left / widthRatio)); } } // Get printer settings and adjust to page size TransformGroup transGroup = new TransformGroup(); layout.CardToPrint.LayoutTransform = transGroup; System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket); transGroup.Children.Add(new ScaleTransform(capabilities.PageImageableArea.ExtentWidth / layout.CardToPrint.Width, capabilities.PageImageableArea.ExtentHeight / layout.CardToPrint.Height)); layout.CardToPrint.LayoutTransform = transGroup; Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); layout.CardToPrint.Measure(sz); layout.CardToPrint.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); // Print card layout printDialog.PrintVisual(layout.CardToPrint, "Results"); }