打印视口

发布于 2024-12-03 12:50:34 字数 1004 浏览 0 评论 0原文

C# wpf 3D Visual Studio 2010 net 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);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-12-10 12:50:34

以下工作有效,现在无论什么,图片都会缩放到纸张的大小
视口的大小

...

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文