![]() |
Click here to advertise with us
|
|
|||||||
| Reporting / Printing Discussion on output-creation components such as reporting, pdf, etc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
|
||||
|
The printing GraphicsUnit is Display, which is 1/100th inch, while the image unit is Pixel. Convert the image measurements to Display units, then you can do the logic math with comparable values. Example:
Code:
Dim img As Image = Image.FromFile("img.bmp")
'image size in 1/100 inch measurement
Dim sz As New SizeF(100 * img.Width / img.HorizontalResolution, _
100 * img.Height / img.VerticalResolution)
Dim p As New PointF((e.PageBounds.Width - sz.Width) / 2, _
(e.PageBounds.Height - sz.Height) / 2)
e.Graphics.DrawImage(img, p)
img.Dispose()
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
||||
|
Good! Here's a short explanation of the measurement systems and the conversion that was done. As mentioned image unit is Pixel, the resolution (HorizontalResolution, VerticalResolution) says how many pixels there is per inch, for display devices also called PPI (pixels per inch), so the relation between these give the inch measurement. Since the numbers in PageBounds/MarginBounds is in scale 1:100 we have to multiply the image sizes by 100 to get values in same scale.
DPI relates to PPI by 1:1 for display devices, a printer can have higher resolution and use multiple ink dots per pixel. For example page width can be 827, which is 8.27in. An image of 400x400 at 150dpi/ppi is 2.67in. wide. The values that is compared in PrintPage handler here would be 827 and 267, and the X value of the point would be (827-267)/2=280.
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
![]() |
| Bookmarks |
| Tags |
| center, graphics, printing, resolution, vb.net |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|