Android gets screenshots and saves them to local SD on card path

Source: Internet
Author: User

/** * Get current screen and save */private void Getandsavecurrentimage () {//1. Build bitmap WindowManager WI          Ndowmanager = Getwindowmanager ();          Display display = Windowmanager.getdefaultdisplay ();          int w = display.getwidth ();          int h = display.getheight ();              Bitmap Bmp = Bitmap.createbitmap (W, H, config.argb_8888);           2. Get the screen View Decorview = This.getwindow (). Getdecorview ();           Decorview.setdrawingcacheenabled (TRUE);           BMP = Decorview.getdrawingcache ();        String Savepath = Getsdcardpath () + "/andydemo/screenimage";              3. Save Bitmap try {file path = new File (Savepath);              File String filepath = savepath + "/screen_1.png";              File File = new file (filepath);              if (!path.exists ()) {path.mkdirs ();              } if (!file.exists ()) {file.createnewfile (); } FILEOUTPUtstream fos = null;              FOS = new FileOutputStream (file);                  if (null! = FOS) {bmp.compress (Bitmap.CompressFormat.PNG, N, FOS);                  Fos.flush ();                    Fos.close ();              Toast.maketext (circleshareactivity.this, "screenshot file saved to sdcard/andydemo/screenimage/", Toast.length_long). Show ();          }} catch (Exception e) {e.printstacktrace (); }}/** * get SDcard folder path function * @return */private String Getsdcardpath () {File Sdcarddir = n        Ull Infers whether SDcard exists as a Boolean sdcardexist = Environment.getexternalstoragestate (). Equals (Android.os.Environment.MEDIA_MOU        NTED);        if (sdcardexist) {sdcarddir = Environment.getexternalstoragedirectory ();    } return sdcarddir.tostring (); }

Android gets and saves it to the local SD on the card path

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.