Windows GDI中的坐標系一文所涉及的代碼

發表于:2007-07-01來源:作者:點擊數: 標簽:
源碼1 /* Function: 把邏輯位置轉換為最終的物理坐標空間中的位置 Parameter: hDC---待轉換邏輯坐標所處的空間 lpPoint---待轉換的邏輯點轉換前為邏輯點,轉換后為取整后的毫米 nCount----待轉換點的個數 RetValue: TRUE or FALSE History: 2003-10-25 11:13

源碼1

/*
 Function:

 把邏輯位置轉換為最終的物理坐標空間中的位置

 Parameter:

 hDC---待轉換邏輯坐標所處的空間

 lpPoint---待轉換的邏輯點轉換前為邏輯點,轉換后為取整后的毫米

 nCount----待轉換點的個數

 RetValue:

 TRUE or FALSE

 History:

 2003-10-25 11:13
*/
void GetPhysicalPosition(HDC hDC,LPPOINT lpPoint ,int nCount)
{
 POINT originPoint;

 int widthmm=GetDeviceCaps(hDC,HORZSIZE);
 int heightmm=GetDeviceCaps(hDC,VERTSIZE);

 int widthres=GetDeviceCaps(hDC,HORZRES);
 int heightres=GetDeviceCaps(hDC,VERTRES);

 LPtoDP(hDC,lpPoint,nCount);

 GetDCOrgEx(hDC,&originPoint);

 for(int i=0; i<nCount; ++i)
 {
  lpPoint[i].x +=originPoint.x;
  lpPoint[i].y +=originPoint.y;

  lpPoint[i].x=lpPoint[i].x*widthmm/widthres;
  lpPoint[i].y=lpPoint[i].y*heightmm/heightres;
 }

}

源碼2
/*
 Function:

  我們自己的把邏輯坐標轉換為設備坐標的函數
*/
BOOL MyLPtoDP(
  HDC hdc,           // handle to device context
  LPPOINT lpPoints,  // array of points
  int nCount         // count of points in array
)
{
 int graphicsMode=GetGraphicsMode(hdc);

 if(graphicsMode ==GM_ADVANCED) //處理啟用了世界坐標系的情況
 {
  XFORM curForm;

  GetWorldTransform(hdc,&curForm);

  for(int i=0; i<nCount; ++i)//應用公式一完成世界坐標空間向頁面坐標空間的轉換
  {
   float xpage=lpPoints[i].x*curForm.eM11+lpPoints[i].y*curForm.eM21+curForm.eDx;
   float ypage=lpPoints[i].x*curForm.eM12+lpPoints[i].y*curForm.eM22+curForm.eDy;

   lpPoints[i].x=(int)xpage;
   lpPoints[i].y=(int)ypage;
  }
 }

 POINT pointOrgView,pointOrgWin;
 SIZE winSize,viewSize;

 //得到窗口、視口的原點和范圍
 GetViewportOrgEx(hdc,&pointOrgView);
 GetViewportExtEx(hdc,&viewSize);
 GetWindowOrgEx(hdc,&pointOrgWin);
 GetWindowExtEx(hdc,&winSize);

 //根據公式二進行頁面坐標空間到設備坐標空間的轉換
 for(int i=0; i<nCount; ++i)
 {
  float xdevice=(lpPoints[i].x-pointOrgWin.x)*viewSize.cx/(float)winSize.cx+pointOrgView.x;
  float ydevice=(lpPoints[i].y-pointOrgWin.y)*viewSize.cy/(float)winSize.cy+pointOrgView.y;

  lpPoints[i].x=(int)xdevice;
  lpPoints[i].y=(int)ydevice;
 
 }

 return TRUE;
}


原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97