[英]Screen shot of transparent application in android
I want to take Screen shot of my transparent application using code. 我想使用代码对透明应用程序进行截屏。 Using this code I am getting the screen shot of outer view only. 使用此代码,我只能得到外部视图的屏幕快照。 Please help 请帮忙
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) {}
try this , it is workin for me to generate file... you can modify as per your requirement 试试这个,生成文件对我来说是工作...您可以根据需要进行修改
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.