c# - 调整图像大小以适合打印页面的问题

标签 c# .net vb.net printing printdocument

我正在尝试使用 PrintDocument 将图像(从文件)打印到打印机。

我正在调整我的图像大小,以便在打印时将其缩放为整页打印输出图像略微裁剪。

编辑 2

使用边距来计算要使用的区域:

With printSettings.DefaultPageSettings
    Dim areaWidth As Single = .Bounds.Width - .Margins.Left - .Margins.Right
    Dim areaHeight As Single = .Bounds.Height - .Margins.Top - .Margins.Bottom
End With

页面的边界为 1169x827 (A4),边距为 1137x795。

调整大小后,我的图像大小为 1092x682,我使用以下代码绘制它: e.Graphics.DrawImage(printBitmap, .Margins.Left, .Margins.Top)

烦人的是,当我打印到 PrintPreviewDialog 时,它可以完美缩放,但是当我将完全相同的代码打印到实际打印机时,它却不适合。

编辑 3

完整代码可以在 this url 找到 用法:

Dim clsPrint As New clsPrinting
    With clsPrint
        .Landscape = True
        .SetMinimumMargins()
        If .ShowPrintDialog Then
            .Documentname = "Some doc name"
            .Preview = False 'When True shows ok
            .PrintImage("filename of a png file")
        End If
    End With

最佳答案

尝试在 PrintPage 函数中使用 e.graphics.VisibleClipBounds 作为可打印页面大小。正如 Hans 所说,最好不要在打印前调整图像大小。

关于c# - 调整图像大小以适合打印页面的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7552512/

相关文章:

c# - page_load 上相当简单的 ASP.NET 异步操作会阻塞 UI

asp.net - ASP : CommandArgument

c# - 在 C# 中避免代码重复 - 通过使用泛型?

c# - 如何获取有关异常的更多信息

c# - Application.OpenForms.Count = 0 总是

c# - 创建基于编译器的非静态版本 "dictionary",其中键是类型

c# - 如何检测/找到 while 循环的结束?

c# - 音标转语音

javascript - 从 JavaScript 按钮调用 WPF 应用程序函数

c# - 通过引用传递的参数使用 P/Invoke 返回垃圾