印刷视 [英] Printing viewport

查看:215
本文介绍了印刷视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#WPF 3D的Visual Studio 2010年净利润4.5

你好

我想打印出我所创建的3D图像,但不能得到它的权利。 所打印的图像被改变大小取决于如何大窗口等。 或对其进行剪裁等。

我想是打印视图端口的打印机上, 拉伸这么宽的纸张,并保持宽高比。

  PrintDialog类对话框=新PrintDialog类();
        如果(dialog.ShowDialog()!=真)
        { 返回; }

        StackPanel中myPanel =新的StackPanel();
        myPanel.Margin =新厚度(40);

        图片MYIMAGE =新的图像();
        myImage.Width = dialog.PrintableAreaWidth  - (2 * MYDPI);
        myImage.Stretch = Stretch.Uniform;
        RenderTargetBitmap BMP =新RenderTargetBitmap((INT)dialog.PrintableAreaWidth,(INT)dialog.PrintableAreaWidth,96,96,PixelFormats.Pbgra32);
        bmp.Render(myViewPort);

        myImage.Source = BMP;

        myPanel.Children.Add(MYIMAGE);

        myPanel.Measure(新尺寸(dialog.PrintableAreaWidth,dialog.PrintableAreaHeight));
        myPanel.Arrange(新的Rect(新点(0,0),myPanel.DesiredSize));

        dialog.PrintVisu​​al(myPanel,MYNAME);
 

解决方案

下面的工作,现在的图片得到缩放到纸张的尺寸,无论 视口的尺寸

...

  PrintDialog类对话框=新PrintDialog类();

        如果(dialog.ShowDialog()!=真)
        {
            返回;
        }


        格之格=新的Grid();

        grid.Margin =新厚度(40);

        //做到这一点的每一列
        ColumnDefinition coldef;
        coldef =新ColumnDefinition();
        coldef.Width =新GridLength(dialog.PrintableAreaWidth,GridUnitType.Pixel);
        grid.ColumnDefinitions.Add(coldef);

        //这样做的每一行
        RowDefinition rowdef;
        rowdef =新RowDefinition();
        rowdef.Height =新GridLength(1,GridUnitType.Auto);
        grid.RowDefinitions.Add(rowdef);
        //
        rowdef =新RowDefinition();
        rowdef.Height =新GridLength(1,GridUnitType.Auto);
        grid.RowDefinitions.Add(rowdef);

        TextBlock的myTitle =新的TextBlock();
        myTitle.FontSize = 24;
        myTitle.FontFamily =新的FontFamily(宋体);
        myTitle.TextAlignment = TextAlignment.Center;
        myTitle.Text = MYNAME;

        grid.Children.Add(myTitle);
        //把它列0,行0
        Grid.SetColumn(myTitle,0);
        Grid.SetRow(myTitle,0);

        图片MYIMAGE =新的图像();
        RenderTargetBitmap BMP =新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);
        //把它列0,行1
        Grid.SetColumn(MYIMAGE,0);
        Grid.SetRow(MYIMAGE,1);

        grid.Measure(新尺寸(dialog.PrintableAreaWidth,dialog.PrintableAreaHeight));
        grid.Arrange(新的Rect(新点(0,0),grid.DesiredSize));

        dialog.PrintVisu​​al(网格,MYNAME);
 

C# wpf 3D visual studio 2010 net 4.5

Hi

I am trying to print out the 3D image I have created but can not get it right. The image that is printed is changing in size depending on how large the window is etc. or it is clipped etc.

What I would like is to print the view port on the printer, stretching it so wide as the paper is and keeping aspect ration.

        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);

解决方案

The following worked, now the picture get scaled to the size of the paper regardless of the size of the viewport

...

        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);

这篇关于印刷视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆