我有一个屏幕捕获方法可以完成一半的工作,它需要屏幕截图,但PNG扩展的图像具有透明背景,而JPEG显示黑色bakground。如何捕捉背景(桌面壁纸)?
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();
}
}