C# – Issues Resizing Image to fit on a printed page

cnetprintdocumentprintingvb.net

I am trying to print an image (from file) to a the printer using a PrintDocument.

I am re-sizing my image so that it is scaled to be full page on the printout when I print this the image is cropped slightly.

EDIT 2

I am using the margins to calculate the area to use:

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

The bounds of the page are 1169×827 (A4) and with the margins it is 1137×795.

After resize my image size is 1092×682 and I am using the following code to draw it:
e.Graphics.DrawImage(printBitmap, .Margins.Left, .Margins.Top)

The annoying thing is that when I print to the PrintPreviewDialog it is scaled perfectly but when I print the exact same code to the actual printer it does not fit.

EDIT 3

Full code can be found at this url
Usage:

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

Best Answer

Try using e.graphics.VisibleClipBounds for the printable page size in the PrintPage function. As Hans said, it's better not to resize your image before printing.