65,210
社区成员
发帖
与我相关
我的任务
分享#define INCH 0.03937float GetDPI(){
HDC hdcScreen;
hdcScreen = CreateDC("DISPLAY",NULL,NULL,NULL);
int iX = GetDeviceCaps(hdcScreen, HORZRES); //pixel
int iY = GetDeviceCaps(hdcScreen, VERTRES); //pixel
int iPhsX = GetDeviceCaps(hdcScreen, HORZSIZE);//mm
int iPhsY = GetDeviceCaps(hdcScreen, VERTSIZE);//mm
if (NULL != hdcScreen){DeleteDC(hdcScreen);}
float iTemp = iPhsX * iPhsX + iPhsY * iPhsY;
float fInch = sqrt(iTemp) * INCH;
iTemp = iX * iX + iY * iY;
float fPixel = sqrt(iTemp);
float iDPI = fPixel/fInch;//dpi=pixel/inch
cout<<"DPI:"<<iDPI<<endl;
return iDPI;
}