android中透明应用的屏幕截图

android中透明应用的屏幕截图,android,view,transparency,screenshot,Android,View,Transparency,Screenshot,我想使用代码拍摄我的透明应用程序的屏幕截图。使用这段代码,我得到的只是外部视图的屏幕截图。请帮忙 View v = getWindow().getDecorView().getRootView(); v.setDrawingCacheEnabled(true); Bitmap b = v.getDrawingCache(); try{ File sdcard = Environment.getExternalStorageDirectory(); File pictureDir

我想使用代码拍摄我的透明应用程序的屏幕截图。使用这段代码,我得到的只是外部视图的屏幕截图。请帮忙

View v = getWindow().getDecorView().getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
try{
    File sdcard = Environment.getExternalStorageDirectory();
    File pictureDir = new File(sdcard, "picopaint");
    pictureDir.mkdirs();
    File f = null;
    for (int i = 1; i < 200; ++i){
        String name = "screen" + i + ".png";
        f = new File(pictureDir, name);
        if (!f.exists()) {                                                         
            break;
        }
    }
    if (!f.exists()) {
        String name = f.getAbsolutePath();
        FileOutputStream fos = new FileOutputStream(name);
        b.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();                                                   
    }
} catch (Exception e) {}

试试这个,它是为我工作生成文件。。。您可以根据需要进行修改

public Bitmap generateFileFromView(View v){

Bitmap bmp = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);   // v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
// create a file to write bitmap data
File file = new File(context.getCacheDir(), "f");
file.createNewFile();

    // Convert bitmap to byte array
Bitmap bitmap = bmp;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
byte[] bitmapdata = bos.toByteArray();

    // write the bytes in file
FileOutputStream fos = new FileOutputStream(file);
fos.write(bitmapdata);
return file;
}

你找到解决办法了吗?我也有这个问题你有代码吗?你找到答案了吗