Android screenshot: Save a view of the contents of the picture and put it on the SD card

Source: Internet
Author: User

The project will occasionally use screenshots to share, so there is the following screenshot of the method ~

The following SaveImage () method is to save the screen of all the contents of the current activity.

private void SaveImage () {

SD Card Save path

String Savepath = environment.getexternalstoragedirectory () + "/temp.png";

ShowProgress ("Please Wait", "saving picture ...");

Savemybitmap (Getbitmapfromrootview (GetWindow () Getdecorview ()), Savepath);

}

Get view and convert to bitmap picture

private static Bitmap Getbitmapfromrootview (view view) {


View.setdrawingcacheenabled (TRUE);

Bitmap bmp = Bitmap.createbitmap (View.getdrawingcache ());

View.setdrawingcacheenabled (FALSE);

if (BMP! = null) {

return BMP;

} else {

return null;

}

}

Save the Bitmao image to the corresponding SD card path

private void Savemybitmap (Bitmap mbitmap, String path) {

File F = new file (path);

try {

F.createnewfile ();

} catch (IOException e) {

E.printstacktrace ();

}

FileOutputStream fOut = null;

try {

FOut = new FileOutputStream (f);

} catch (FileNotFoundException e) {

E.printstacktrace ();

}

if (Mbitmap!=null) {

Save format is 100 PNG quality

Mbitmap.compress (Bitmap.CompressFormat.PNG, FOut);

}

try {

Fout.flush ();

} catch (IOException e) {

E.printstacktrace ();

}

try {

Fout.close ();

} catch (IOException e) {

E.printstacktrace ();

}

}

Android screenshot: Save a view of the contents of the picture and put it on the SD card

Related Article

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.