【问题标题】:.NET printing coordinate conversion.NET打印坐标转换
【发布时间】:2011-08-23 10:49:55
【问题描述】:

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

在我的印刷活动中,我这样做:

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,1192) 不会是一个非常宽的图像(1 像素)。
  • 不,你没有得到这个问题。图像很好,50x50 像素,问题在于从像素到打印系统期望的坐标转换。

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


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多