2013-08-13 2 views
3

코드를 작성하여 스크린 샷을 캡처하고이를 WPF의 비트 맵 파일에 저장했습니다.비트 맵 파일 인쇄

이제 비트 맵을 프린터의 페이지 크기로 조정 된 프린터로 보내려고합니다.

WPF 및 C#에서 어떻게 수행 할 수 있습니까?

힌트 또는 약간의 코드를 제공 할 수 있다면 가장 좋을 것 같습니다.

인사말 세바스찬

답변

5
당신은

This article

대화

PrintDialog dialog = new PrintDialog(); 
if (dialog.ShowDialog() == true) 
{ dialog.PrintVisual(_PrintCanvas, "My Canvas"); } 

또는 귀하의 경우에는 그것을 할 방법을 설명합니다 (열 인쇄 대화 상자) 사용자를 묻지 않고 인쇄 할 수 없습니다

private void PrintSomethingNew() 
{ 
  PrintDialog dialog = new PrintDialog(); 
  if (dialog.ShowDialog() != true) 
  { return; } 

  StackPanel myPanel = new StackPanel(); 
  myPanel.Margin = new Thickness(15); 
  Image myImage = new Image(); 
  myImage.Width = 128; 
  myImage.Stretch = Stretch.Uniform; 
  myImage.Source = new BitmapImage(new Uri("C:\\Tree.jpg", UriKind.Absolute)); 
  myPanel.Children.Add(myImage); 
  TextBlock myBlock = new TextBlock(); 
  myBlock.Text = "A Great Image."; 
  myBlock.TextAlignment = TextAlignment.Center; 
  myPanel.Children.Add(myBlock); 

  myPanel.Measure(new Size(dialog.PrintableAreaWidth, 
    dialog.PrintableAreaHeight)); 
  myPanel.Arrange(new Rect(new Point(0, 0),  
    myPanel.DesiredSize)); 

  dialog.PrintVisual(myPanel, "A Great Image."); 
}