I have a screen capture method that does half the job, it takes the screen shot but the images with PNG extention have transparent background and with JPEG it displays Black bakground. How can I capture the background (desktop wallpaper) ?
public void takeScreenshot() throws IOException {
date = new DateIAinnot();
view = ((Activity) context).getWindow().getDecorView().getRootView();
view.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
root = Environment.getExternalStorageDirectory().toString();
myDir = new File(root + "/Pictures");
myDir.mkdirs();
fname = date.getDate(2) + ".png";
fname = fname.replace(':', '_');
fname = fname.replace(' ', '-');
file = new File(myDir, fname);
if (file.exists()) file.delete();
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
openScreenshot(file);
} catch (Exception e) {
e.printStackTrace();
}
}