1

我无法得到一个简单的答案。我有像素坐标,我想在这些坐标的(横向)页面中打印图像。

在我的印刷活动中,我会:

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

有什么提示吗?谢谢。

4

1 回答 1

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
于 2011-08-23T13:49:34.730 回答