First you need to understand what the dip and PX mean.
Dip:device independent pixels (device independent pixels). Different devices have different display effects, and this is related to device hardware.
Px:pixels (pixels), different devices different display display effect is the same, this is absolute pixels, is how much will never change.
Dip conversion: dip = (int) (px/1.5 + 0.5).
The detailed introduction can refer to http://www.cnblogs.com/error404/archive/2011/11/03/2234165.html.
Then use C + + code to implement the above conversion formula
#include <iostream>#include<string>using namespacestd;voidMain () {floatPX =0; floatDip =0; cout<<"-----------------------------------"<<Endl; cout<<"Please enter the pixel value (px) input 0 exit the program"<<Endl; CIN>>px; while(px! =0) {Dip= (px/1.5f+0.5f); cout<<"the values for the calculated dip are:"<<Endl; cout<<dip<<Endl; cout<<"-----------------------------------"<<Endl; cout<<"Please enter the pixel value (px) input 0 exit the program"<<Endl; CIN>>px; } return ;}
In order to be able to calculate multiple times, the code uses a while loop to detect user input if the user enters 0 to exit the program.
C + + implements the small program of PX conversion to dip function in Android