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