public static Bitmap captureScreen(View v) {
Bitmap screenshot = null;
try {
if(v!=null) {
screenshot = Bitmap.createBitmap(V. getMeasuredWidth(),V. getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(screenshot);
v.draw(canvas);
}
}catch (Exception e){
Log.d("DalActivity", "Error:" + e.getMessage());
}
return screenshot;
}
public static void saveImage(Bitmap bitmap) throws IOException{
Time time = new Time();
time.setToNow();
//ByteArrayOutputStream bytes = new ByteArrayOutputStream();
//bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File f = new File(Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),Integer.toString(time.year) +"."+ Integer.toString(time.month) +"."+ Integer.toString(time.monthDay) +" "+ Integer.toString(time.hour) +":"+ Integer.toString(time.minute)+":" + Integer.toString(time.second) + ".png");
//f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fo);
//fo.write(bytes.toByteArray());
fo.close();
}
Find more questions by tags Android