2011-09-06 80 views
1

C#WPF 3D的Visual Studio 2010年淨利潤4.5印刷視

我想打印出我所創建的3D圖像,但不能得到它的權利。 被打印的圖像根據窗口有多大等等 或對其進行剪裁等的改變大小

我想是在打印機上打印的視口, 拉伸它如此寬該文件是保持長寬比。

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

     StackPanel myPanel = new StackPanel(); 
     myPanel.Margin = new Thickness(40); 

     Image myImage = new Image(); 
     myImage.Width = dialog.PrintableAreaWidth - (2 * MYDPI); 
     myImage.Stretch = Stretch.Uniform; 
     RenderTargetBitmap bmp = new RenderTargetBitmap((int)dialog.PrintableAreaWidth, (int)dialog.PrintableAreaWidth, 96, 96, PixelFormats.Pbgra32); 
     bmp.Render(myViewPort); 

     myImage.Source = bmp; 

     myPanel.Children.Add(myImage); 

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

     dialog.PrintVisual(myPanel, myName); 
+0

如果您知道要打印的區域,爲什麼你不只是截取該區域的屏幕截圖並進行打印呢? –

+0

這就是發生在 RenderTargetBitmap bmp = new RenderTargetBitmap((int)dialog.PrintableAreaWidth,(int)dialog.PrintableAreaWidth,96,96,PixelFormats.Pbgra32); bmp.Render(myViewPort); –

回答

2

下面的工作,現在的畫面效果是縮放後的紙張尺寸無論 視

的大小...

 PrintDialog dialog = new PrintDialog(); 

     if (dialog.ShowDialog() != true) 
     { 
      return; 
     } 


     Grid grid = new Grid(); 

     grid.Margin = new Thickness(40); 

     //do this for each column 
     ColumnDefinition coldef; 
     coldef = new ColumnDefinition(); 
     coldef.Width = new GridLength(dialog.PrintableAreaWidth, GridUnitType.Pixel); 
     grid.ColumnDefinitions.Add(coldef); 

     //do this for each row 
     RowDefinition rowdef; 
     rowdef = new RowDefinition(); 
     rowdef.Height = new GridLength(1, GridUnitType.Auto); 
     grid.RowDefinitions.Add(rowdef); 
     // 
     rowdef = new RowDefinition(); 
     rowdef.Height = new GridLength(1, GridUnitType.Auto); 
     grid.RowDefinitions.Add(rowdef); 

     TextBlock myTitle = new TextBlock(); 
     myTitle.FontSize = 24; 
     myTitle.FontFamily = new FontFamily("Arial"); 
     myTitle.TextAlignment = TextAlignment.Center; 
     myTitle.Text = myName; 

     grid.Children.Add(myTitle); 
     //put it in column 0, row 0 
     Grid.SetColumn(myTitle, 0); 
     Grid.SetRow(myTitle, 0); 

     Image myImage = new Image(); 
     RenderTargetBitmap bmp = new RenderTargetBitmap((int)this.Width, (int)this.Height, 96, 96, PixelFormats.Pbgra32); 
     bmp.Render(myViewPort); 

     myImage.Source = bmp; 
     myImage.Stretch = Stretch.Uniform; 

     grid.Children.Add(myImage); 
     //put it in column 0, row 1 
     Grid.SetColumn(myImage, 0); 
     Grid.SetRow(myImage, 1); 

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

     dialog.PrintVisual(grid, myName);