关于gdi+与gdi坐标系的问题

haibinxx 2014-12-29 11:07:58
pDC->Rectangle(x, y, x+w, y+h);
m_pGraphics->DrawRectangle(m_pGdiplusPen, (int)x, y, w, h);

我在GDI+下绘制矩形,想要得到与GDI环境下第一条语句一样的效果,所有的设置均是默认(坐标系),在屏幕渲染环境下,两个语句执行的相同效果,但是在打印输出的时候,GDI是对的,GDI+缺打印不出任何东西,请大家帮看看怎么解决,语句中的x、y传进去的均是设备坐标
...全文
116 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-12-30
  • 打赏
  • 举报
回复
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/gdicpp/GDIPlus/aboutGDIPlus/coordinatesystemsandtransformations/typesofcoordinatesystems.htm 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. 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. 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. 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. 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). 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()). 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: 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). 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: World (0, 0) to (2, 1) Page (2, 0.5) to (4, 1.5) Device (192, 48) to (384, 144) --------------------------------------------------------------------------------

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧