View Single Post
  #1 (permalink)  
Old 01-14-2009, 4:00 PM
Mijul Thomas Mijul Thomas is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Posts: 7
Reputation: 0
Mijul Thomas is on a distinguished programming path ahead
Default VB.Net - Printing, Graphics, Centering, and Resolutions

Microsoft Visual Studio 2008 Professional
VB.Net
Windows XP SP2


Hi,

I am coding an application to print graphics centered both vertically and horizontally on the paper.
Sounds pretty simple, right? Yes. Well, unfortunately, I have run into a problem concerning the resolution/DPI of the images. and printing

- All images must be 150 DPI.
- The graphics MUST not be resized to fit the paper.
- Graphics are not all the same dimensions. Some are 1200x1200, some 600x400, some 30x1200, and so on.
- Paper size reports to me as 850x1100 px, but the paper size will not be limited to just that.

So my question:
What algorithm or calculations should I perform to print 150 DPI graphics centered on a paper?


Here is what I currently have which would logically seem to work, but does not:

--------------------------------------------------------------------------
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim img As Image = Image.FromFile(glbImgGetFile)
Dim px As Integer = (e.PageBounds.Width - img.Width) / 2
Dim py As Integer = (e.PageBounds.Height - img.Height) / 2
e.Graphics.DrawImage(img, px, py)
End Sub

--------------------------------------------------------------------------

The above code works great for graphics with a DPI of 72 or 96, but does not work for graphics with a DPI of 150, which I need them to be in. They are shifted to the left for some odd reason...

Any help or ideas will be appreciated.


Thanks,
M. Thomas
Reply With Quote