I am using the standard android code to take a screenshot of a Processing application:
private void Screenshot() {
try {
String mPath = Environment.getExternalStorageDirectory().toString() + "/screenshot.jpg";
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
The code is working, the screenshot is taken, it is about 13kB in size. Howeever, it is all black, no matter the contents on the screen.
Do you know how to solve the issue? Maybe the canvas should be accessed in a different way than using:
View v1 = getWindow().getDecorView().getRootView();
?
Thank you in advance for your help.