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