C + + implements the small program of PX conversion to dip function in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.