gpt4 book ai didi

c# - PrintFixedDocument wpf 打印质量- Windows 10/8 与 Windows 7

转载 作者:可可西里 更新时间:2023-11-01 12:42:09 27 4
gpt4 key购买 nike

我目前正在尝试使用 PrintFixedDocument 打印内容容器的内容(它只包含带有信息的数据网格)和图像。它在我的机器 (Windows 10) 上以完整的图像质量完美打印,而在另一台 Windows 8 电脑上,质量是一样的。

然而,当在 Windows 7 电脑上完成此操作时,图像质量会变得很差,最终结果会非常模糊。这是一个问题,因为由于各种原因无法从 Windows 7 更新计算机,所以我想知道是否有其他人遇到过这种情况,如果有,是否有解决方法?也可能是我的 GetFixedDocument 方法的问题,尽管我无法弄清楚为什么这对 win 10 和 8 都有效,但对 7 无效。

注意这是从每台 PC 上安装的应用程序版本运行

还在所有 3 个操作系统上的多台打印机上进行了测试

任何帮助将不胜感激

Xaml:

            <StackPanel Margin="-105,146,66,0" Height="900" VerticalAlignment="Top"  x:Name="PrintImageContextMenu">
<Image Canvas.ZIndex="0" Source="{Binding Coupon.OverlayImagePath}" Margin="0,-21,-76,108" Stretch="Fill" />

<ContentControl Content="{Binding}" ContentTemplateSelector="{StaticResource DataViewerDataTemplateSelector}" />

</StackPanel>

C#: 公共(public)部分类 CouponViewerView { 公共(public) CouponViewerView() { 初始化组件();

    public void Print()
{
//Executes On Thread
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (EventHandler)delegate
{
UpdateLayout();

var fixedDoc = PrintHelper.GetFixedDocument(StackPanelToPrint, new PrintDialog());

PrintHelper.ShowPrintPreview(fixedDoc);


}, null, null);



}

private void PrintCurrentForm(object sender, RoutedEventArgs e)
{
Print();
}

C# 打印助手代码:

 public static void ShowPrintPreview(FixedDocument fixedDoc)
{
var wnd = new Window();
var viewer = new DocumentViewer();
viewer.Document = fixedDoc;
wnd.Content = viewer;
wnd.ShowDialog();
}


public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog)
{
var capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
var pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
var visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
var fixedDoc = new FixedDocument();
//If the toPrint visual is not displayed on screen we neeed to measure and arrange it
toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize));
//
var size = toPrint.DesiredSize;
//Will assume for simplicity the control fits horizontally on the page
double yOffset = 0;
while (yOffset < size.Height)
{
var vb = new VisualBrush(toPrint)
{
Stretch = Stretch.None,
AlignmentX = AlignmentX.Left,
AlignmentY = AlignmentY.Top,
ViewboxUnits = BrushMappingMode.Absolute,
TileMode = TileMode.None,
Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height)
};
var pageContent = new PageContent();
var page = new FixedPage();
((IAddChild)pageContent).AddChild(page);
fixedDoc.Pages.Add(pageContent);
page.Width = pageSize.Width;
page.Height = pageSize.Height;
var canvas = new Canvas();
FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
canvas.Width = visibleSize.Width;
canvas.Height = visibleSize.Height;
canvas.Background = vb;
page.Children.Add(canvas);
yOffset += visibleSize.Height;
}
return fixedDoc;
}

最佳答案

anyone else has experienced this and if so is there a workaround?

这是唯一可以直接回答的问题,是的,很多。请记住,您经常会在打印机上大幅重新调整图像,与显示器相比,它们是每英寸点数分辨率非常高的设备。启动 Win7 的机器通常以 96dpi 运行,后来的机器往往有更好的显示器,因此通常以更高的 dpi 设置运行。首先要注意的是源图像。如果它的像素大小适合该 Win7 PC,那么当它放大到 600 dpi 时它会变得非常模糊。

WPF 中最不直观的缩放行为可能是图像对齐在缩放后与目标像素不完全匹配时发生的情况。 this blog post 中描述的问题.请务必同时阅读 this SO question ,几乎完美适合您对 VisualBrush 的使用及其模糊问题。此问题已在 .NET 4.0 中通过添加 UseLayoutRounding 得到解决。属性(property)。你没有使用它,你绝对应该。不要盲目应用 dup 推荐的 BitmapScalingMode,图像类型(艺术线条与照片)很重要。

关于c# - PrintFixedDocument wpf 打印质量- Windows 10/8 与 Windows 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34226043/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com