'Background transparency not correctly displaying in screenshot
I'm using the code below to take a screenshot of my android screen. The background of my app is transparent, thus allowing the underlining screen to show through. In this case, the background is the home screen of my emulator.
When the "SNAP" button is pressed, it only captures my app and not any of the background. How can I get the background to show up in my screenshot?
btSnap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
final Bitmap b = Bitmap.createBitmap( view.getHeight(), view.getWidth(), Bitmap.Config.ARGB_8888);
PixelCopy.request(getWindow(), b, (int result) -> {
if (result != PixelCopy.SUCCESS) {
Toast.makeText(MainActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
return;
}
try {
try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
b.compress(Bitmap.CompressFormat.PNG, 100, out);
}
} catch (Exception e) {
e.printStackTrace();
}
}, view.getHandler());
//openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or DOM
e.printStackTrace();
}
}
});
View of android emulator before "SNAP" button pressed.
The file produced by pressing the snap button.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


