我試圖打印大小爲2x2英寸的圖像。根據分辨率創建一個轉換函數(英寸到像素)。但是,結果遠不是2x2英寸,印刷產生的圖像幾乎不適合整張紙!我做錯了什麼?PrintDocument_PrintPage&Graphics.DrawImage大小以英寸爲單位
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim graph = e.Graphics
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
Dim photo = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Koala.jpg")
graph.DrawImage(photo, New RectangleF(0, 0, InchToPx(graph.DpiX, 2), InchToPx(graph.DpiY, 2)))
End Sub
Private Function InchToPx(ByVal dpi As Single, ByVal inches As Single) As Single
Return (inches * dpi)
End Function
*通用分辨率爲顯示器是96 dpi * >>注意,這確實是* common *,但許多人(尤其是視力問題)已將此設置爲120 dpi或更高,並且Mac(不是.NET可能的候選人,但仍然是Silverlight在Mac上運行)默認情況下使用72 dpi,並且*「相同大小」*僅爲相對值,屏幕上的像素大小差別很大PS:+1正確答案! – Abel 2010-08-16 11:31:21