.NET打印坐标转换

时间:2011-08-23 10:49:56

标签: .net vb.net printing coordinate-transformation

我无法得到一个简单的答案。 我有像素坐标,我想在那些坐标的(风景)页面上打印图像。

在我的印刷活动中,我做了:

Dim mypoint As New PointF(1, 1192)
e.Graphics.DrawImage(My.Resources.littleSquare, mypoint)

这显然不起作用:我指定像素,但驱动程序需要英寸(?)或什么?

试图:e.Graphics.PageUnit = GraphicsUnit.Inch没有运气。

我想要一种转换方法,如:

Dim mypoint As New PointF(convertPixelsIntoInches(1), convertPixelsIntoInches(1192))
e.Graphics.DrawImage(My.Resources.littleSquare, mypoint)

Private Function convertPixelsIntoInches(ByVal pixels As Integer) As Single
    Return ??
End Function

任何提示?感谢。

1 个答案:

答案 0 :(得分:1)

我想我明白了。

我的像素坐标不固定,但相对于300dpi画布,因此我必须进行双DPI转换,如下所示:

e.Graphics.PageUnit = GraphicsUnit.Pixel
dpiX = e.Graphics.DpiX
dpiY = e.Graphics.DpiY

Dim mypoint As New PointF(convertPixelsIntoInchesX(1501), convertPixelsIntoInchesY(1192))
e.Graphics.DrawImage(My.Resources.myblacksquare, mypoint)

Private Function convertPixelsIntoInchesX(ByVal pixel As Integer) As Single
   Return CSng(pixel * dpiX / 300)
End Function

Private Function convertPixelsIntoInchesY(ByVal pixel As Integer) As Single
        Return CSng(pixel * dpiY / 300)
End Function
相关问题