kubaork
kubaork

Reputation: 161

Android how can I get screenshot bitmap?

To make screenshots I use this code:

Process sh = Runtime.getRuntime().exec("su", null,null);

OutputStream  os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();

os.close();
sh.waitFor();

But this is veeery slow! Maybe because phone is saving this image on storage. To get this bitmap I use this code:

bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+         
File.separator +"img.png");

But that's pretty slow! Is possible to get bitmap but not save it? Maybe it will be much faster?

Upvotes: 1

Views: 900

Answers (1)

martyglaubitz
martyglaubitz

Reputation: 1002

here you go View.getDrawingCache() returns the currently drawn View suface.

view.setsetDrawingCacheEnabled(true);
final Bitmap screenshot = view.getDrawingCache();
view.setDrawingCacheEnabled(false);    

//use bitmap

Upvotes: 1

Related Questions