Public Code Reference (displaymetrics)

Source: Internet
Author: User

 PackageCom.fredric.util;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.graphics.Bitmap;ImportAndroid.util.DisplayMetrics;ImportAndroid.view.View;ImportAndroid.view.WindowManager;/*-* Screen interaction class Encapsulation*/ Public classScreenutils {//Get screen width     Public Static intGetscreenwidth (Context context) {WindowManager WM=(WindowManager) context. Getsystemservice (Context.window_service); //Displaymetrics provides general information about the realityDisplaymetrics display =NewDisplaymetrics (); //Place the current window information in displayWm.getdefaultdisplay (). Getmetrics (display); //returns absolute pixels        returnDisplay.widthpixels; }        //Get screen height     Public Static intGetscreenheight (Context context) {WindowManager WM=(WindowManager) context. Getsystemservice (Context.window_service); Displaymetrics Display=NewDisplaymetrics ();        Wm.getdefaultdisplay (). Getmetrics (display); returnDisplay.heightpixels; }        //Screen Cutting     Public StaticBitmap getsnapshot (activity activity) {//Decorview is the topmost view of windowView view =Activity.getwindow (). Getdecorview (); //the contents of the view component are saved to bitmap via the cache mechanism//setdrawingcacheenabled Open Cache//Getdrawingcache Get the cache picture for view//Builddrawingcache is not called, if the cache is not established when Getdrawingcache is called//Destorydrawingcache Destroy cache,setdrawingcacheenabled (false) can also destroy cache//cache to update you must first destroy the old cacheView.setdrawingcacheenabled (true); Bitmap BP=NULL; intwidth =getscreenwidth (activity); intHeight =getscreenheight (activity); BP= Bitmap.createbitmap (View.getdrawingcache (), 0, 0, width, height);          View.destroydrawingcache (); returnBP; }}

Public Code Reference (displaymetrics)

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.