2012-12-06 76 views
1

我想使用代码拍摄透明应用程序的屏幕截图。使用这段代码,我只能看到外部视图的屏幕截图。请帮助Android中的透明应用程序的屏幕截图

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) {} 
+0

你现在得到修改? – Ishtiaq

+0

你有没有找到解决方案? – Wops

+0

我也有这个问题你有代码为 – anddevmanu

回答

0

试试这个,这是干活,我生成文件...您可以按照您的要求

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; 
} 
+0

不适合我 –

相关问题