Tool class DP to PX get picture actual size get screen size

Source: Internet
Author: User

DP Turn px

 Public classDp2pxutils { Public Static intDP2PX (Context context,floatDP) {        Final floatScale =context.getresources (). Getdisplaymetrics (). density; return(int) (DP * scale + 0.5f); }    /*** According to the resolution of the phone from PX (pixel) to the unit to become DP*/     Public Static intPx2dip (Context context,floatpxvalue) {        Final floatScale =context.getresources (). Getdisplaymetrics (). density; return(int) (Pxvalue/scale + 0.5f); }}

Get the actual size of the picture

 Public classImgutils {/*** Use bitmap to obtain the original width and height of the picture*/     Public Static intgetimgoriginalwidth (String path) {bitmapfactory.options Options=Newbitmapfactory.options (); //set to True to resolve the bitmap object, which does not account for memoryOptions.injustdecodebounds =true;        Bitmapfactory.decodefile (path, options); intBitmapwidth =Options.outwidth; returnBitmapwidth; }    /*** Use bitmap to obtain the original width and height of the picture*/     Public Static intgetimgoriginalheight (String path) {bitmapfactory.options Options=Newbitmapfactory.options (); //set to True to resolve the bitmap object, which does not account for memoryOptions.injustdecodebounds =true;        Bitmapfactory.decodefile (path, options); intBitmapheight =Options.outheight; returnBitmapheight; }    }
 Public classImgutils {/*** Use bitmap to obtain the original width and height of the picture*/     Public Static intgetimgoriginalwidth (String path) {bitmapfactory.options Options=Newbitmapfactory.options (); //set to True to resolve the bitmap object, which does not account for memoryOptions.injustdecodebounds =true;        Bitmapfactory.decodefile (path, options); intBitmapwidth =Options.outwidth; returnBitmapwidth; }    /*** Use bitmap to obtain the original width and height of the picture*/     Public Static intgetimgoriginalheight (String path) {bitmapfactory.options Options=Newbitmapfactory.options (); //set to True to resolve the bitmap object, which does not account for memoryOptions.injustdecodebounds =true;        Bitmapfactory.decodefile (path, options); intBitmapheight =Options.outheight; returnBitmapheight; }    }

Get screen Size

 Public classScreenutil { Public Static intGetscreenhight (Context context) {Displaymetrics Displaymetrics=NewDisplaymetrics (); ((WindowManager) Context.getsystemservice (Context.window_service)). Getdefaultdisplay (). GetMetrics (        Displaymetrics); returnDisplaymetrics.heightpixels; }     Public Static intGetscreenwidth (Context context) {Displaymetrics Displaymetrics=NewDisplaymetrics (); ((WindowManager) Context.getsystemservice (Context.window_service)). Getdefaultdisplay (). GetMetrics (        Displaymetrics); returnDisplaymetrics.widthpixels; }}

Tool class DP to PX get picture actual size get screen size

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.