Microsoft Windows 坐标空间 (翻译自MSDN)

Types of Coordinate Systems


Microsoft Windows GDI+ uses three coordinate spaces: world, page, and device. When you make the call myGraphics.DrawLine(&myPen, 0, 0, 160, 80), the points that you pass to the DrawLine method — (0, 0) and (160, 80) — are in the world coordinate space. Before GDI+ can draw the line on the screen, the coordinates pass through a sequence of transformations. One transformation converts world coordinates to page coordinates, and another transformation converts page coordinates to device coordinates.

Microsoft Windows GDI+使用三种坐标空间:世界,页面,设备。当你调用函数myGraphics.DrawLine(&myPen, 0, 0, 160, 80)时,你传递给DrawLine的两个点(00),(16080)是世界坐标空间的点。在GDI+能够把它画到屏幕上之前,它要经过一个转换序列,一个转换是将世界坐标空间转换到页面坐标空间,一个转换是将页面坐标空间转换成设备坐标空间。

Suppose you want to work with a coordinate system that has its origin in the body of the client area rather than the upper-left corner. Say, for example, that you want the origin to be 100 pixels from the left edge of the client area and 50 pixels from the top of the client area. The following illustration shows such a coordinate system.

假设你想要用一个坐标系,但是它的原点不在左上角而是在客户区。比如说:你想要把原点设定在离左边100像素,离上边50像素,下面的插图就显示了这个坐标系。

When you make the call myGraphics.DrawLine(&myPen, 0, 0, 160, 80), you get the line shown in the following illustration.

The coordinates of the endpoints of your line in the three coordinate spaces are as follows:

你在不同坐标系下的终点坐标如下:

World

(0, 0) to (160, 80)

Page

(100, 50) to (260, 130)

Device

(100, 50) to (260, 130)

Note that the page coordinate space has its origin at the upper-left corner of the client area; this will always be the case. Also note that because the unit of measure is the pixel, the device coordinates are the same as the page coordinates. If you set the unit of measure to something other than pixels (for example, inches), then the device coordinates will be different from the page coordinates.

注意到页面坐标空间将它的坐标原点设定在客户区的左上角,这将总会是这样。我们还注意到由于度量的单元是像素,设备坐标空间与页面坐标空间相同,如果你将度量的单元设置成别的而不是像素(比如英尺),那样设备坐标空间就与页面坐标空间不同了。

The transformation that maps world coordinates to page coordinates is called the world transformation and is maintained by a Graphics object. In the previous example, the world transformation is a translation 100 units in the x direction and 50 units in the y direction. The following example sets the world transformation of a Graphics object and then uses that Graphics object to draw the line shown in the previous figure.

这种把世界坐标空间转换成页面坐标空间的映射被称作世界转换,被图形对象操作。在先前的例子中,世界转换是一个x轴方向100个单位和y轴方向50个单位的转换。下面的例子设置了一个Graphic object的世界转换,然后用Graphic object绘制在前面插图中显示的那条直线

myGraphics.TranslateTransform(100.0f, 50.0f);

 

myGraphics.DrawLine(&myPen, 0, 0, 160, 80);

The transformation that maps page coordinates to device coordinates is called the page transformation. The Graphics class provides four methods for manipulating and inspecting the page transformation: SetPageUnit, GetPageUnit, SetPageScale, and GetPageScale. The Graphics class also provides two methods, GetDpiX and GetDpiY, for examining the horizontal and vertical dots per inch of the display device.

这种把页面坐标到设备坐标的转换被称作页面转换Graphic类提供了四个方法来操作和检查页面转换:SetPageUnit,GetPageUnit,SetPageScale,GetPageScaleGraphic类还提供了两种方法:GetDpiXGetDpiY,来检查显示设备每英寸上水平和垂直的像素点数目。

You can use the SetPageUnit method of the Graphics class to specify a unit of measure. The following example draws a line from (0, 0) to (2, 1) where the point (2, 1) is 2 inches to the right and 1 inch down from the point (0, 0).

你可以使用Graphic类的SetPageUnit方法来指定度量的单位。下面的例子画了一条从(00)到(21)的直线,点(21)表示离点(00)左边2英寸,右边1英寸。

myGraphics.SetPageUnit(UnitInch);

 

myGraphics.DrawLine(&myPen, 0, 0, 2, 1);

Note   If you don't specify a pen width when you construct your pen, the previous example will draw a line that is one inch wide. You can specify the pen width in the second argument to the Pen constructor:

Pen myPen(Color(255, 0, 0, 0), 1/myGraphics.GetDpiX()).

备注:如果你创建一个Pen时不指定Pen的宽度,前面的例子会画一个里英寸宽的线。你可以在Pen的构造函数中的第二个参数指定Pen的宽度

If we assume that the display device has 96 dots per inch in the horizontal direction and 96 dots per inch in the vertical direction, the endpoints of the line in the previous example have the following coordinates in the three coordinate spaces:

如果我们假定显示设备在水平和垂直方向都是每英寸96像素点,前面例子中的终点在三个坐标空间坐标如下:

World

(0, 0) to (2, 1)

Page

(0, 0) to (2, 1)

Device

(0, 0, to (192, 96)

You can combine the world and page transformations to achieve a variety of effects. For example, suppose you want to use inches as the unit of measure and you want the origin of your coordinate system to be 2 inches from the left edge of the client area and 1/2 inch from the top of the client area. The following example sets the world and page transformations of a Graphics object and then draws a line from (0, 0) to (2, 1).

你可以把世界坐标空间和页面坐标空间结合起来来得到多种效果。例如:假设你想要把英寸作为度量的单位,而且你想要你的坐标系的原点在离客户区左边2英寸,离客户区顶端1/2英寸的点。下面的例子设定了一个Graphic 对象的世界和页面转换,然后画了一条从(00)到(21)的直线。

 

myGraphics.TranslateTransform(2.0f, 0.5f);

myGraphics.SetPageUnit(UnitInch);

myGraphics.DrawLine(&myPen, 0, 0, 2, 1);

The following illustration shows the line and coordinate system.

下面的插图显示了直线和坐标系。

If we assume that the display device has 96 dots per inch in the horizontal direction and 96 dots per inch in the vertical direction, the endpoints of the line in the previous example have the following coordinates in the three coordinate spaces:

如果我们假定显示设备水平和垂直方向都是每英寸96个像素点,前面例子直线的终点的在三个坐标空间坐标如下:

World

(0, 0) to (2, 1)

Page

(2, 0.5) to (4, 1.5)

Device

(192, 48) to (384, 144)


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值