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