Ok, This has to do with the declared size of the image and the way that
DrawImage interprets size and resolution. I fixed the problem by drawing in
pixels only.
After my signature you'll find the amended routine.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
----------------------------------------------------------------------------
-----
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
'Load the image from file
Dim _Image As Image = i
'Calculate the values needed for best-fit
Dim PrintWidth As Single = CType(e.PageSettings.PaperSize.Width, Single) ' /
100 * e.Graphics.DpiX
Dim PrintHeight As Single = CType(e.PageSettings.PaperSize.Height, Single) '
/ 100 * e.Graphics.DpiY
Dim WidthRatio As Double = _Image.Width / PrintWidth
Dim HeigthRatio As Double = _Image.Height / PrintHeight
Dim largestRatio As Double
largestRatio = Math.Max(WidthRatio, HeigthRatio)
Dim posX As Single = CType((PrintWidth * largestRatio / 2 - _Image.Width /
2), Single)
Dim posY As Single = CType((PrintHeight * largestRatio / 2 - _Image.Height /
2), Single)
'Help me...I don't understand how the Matrix or Transform work.
Dim mx As New Matrix(1.0F / CType(largestRatio, Single), 0, 0, 1.0F /
CType(largestRatio, Single), 0, 0)
mx.Translate(posX, posY)
e.Graphics.Transform = mx
' Draw the image as large as you can but maintain aspect ratio of the image
from file.
e.Graphics.DrawImage(_Image, New Rectangle(0, 0, i.Width, i.Height), 0, 0,
i.Width, i.Height, GraphicsUnit.Pixel)
e.HasMorePages = False
End Sub
----------------------------------------------------------------------------
-----
[quoted text, click to view] "Doug DeBug" <n_sp_m_sales@scantiva.com> wrote in message
news:93217387.0411281822.1b4edcb8@posting.google.com...
> I would like to print an image as large as I can on any size of paper
> (user selected or default printer settings). The following code is
> based on Bob Powell's C# example. However, the image is too small
>
> Help!!!!
>
>
>
>
> Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e
> As System.Drawing.Printing.PrintPageEventArgs) Handles
> PrintDocument1.PrintPage
> 'Load the image from file
> Dim _Image As Image = _Image.FromFile(ImageToPrint)
>
> 'Calculate the values needed for best-fit
> Dim PrintWidth As Single =
> CType(e.PageSettings.PaperSize.Width, Single)
> Dim PrintHeight As Single =
> CType(e.PageSettings.PaperSize.Height, Single)
> Dim WidthRatio As Double = _image.Width / PrintWidth
> Dim HeigthRatio As Double = _image.Height / PrintHeight
> Dim largestRatio As Double
> largestRatio = Math.Max(WidthRatio, HeigthRatio)
>
> Dim posX As Single = CType((PrintWidth * largestRatio / 2 -
> _image.Width / 2), Single)
> Dim posY As Single = CType((PrintHeight * largestRatio / 2 -
> _Image.Height / 2), Single)
>
> 'Help me...I don't understand how the Matrix or Transform
> work.
> Dim mx As New Matrix(1.0F / CType(largestRatio, Single), 0, 0,
> 1.0F / CType(largestRatio, Single), 0, 0)
> mx.Translate(posX, posY)
> e.Graphics.Transform = mx
> ' Draw the image as large as you can but maintain aspect ratio
> of the image from file.
> e.Graphics.DrawImage(_image, 0, 0)
> e.HasMorePages = False
> End Sub
>
>
> Thanks!!!
>
>
> n_sp_m_doug.daly@scantiva.com