在我的应用程序中,我想捕获带有surfaceview的屏幕,但我无法捕获使用背景绘制的屏幕。如何保存与背景一起绘制的屏幕。请帮助我如何解决这个问题。
View content = findViewById(R.id.relative21);
content.setDrawingCacheEnabled(true);
SurfaceHolder sfhTrack = drawingSurface.getHolder();
sfhTrack.setFormat(PixelFormat.TRANSPARENT);
private void getScreen() {
// TODO Auto-generated method stub
View content = findViewById(R.id.relative21);
Bitmap bitmap = content.getDrawingCache();
File myDir=new File("/sdcard/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".png";
File file = new File (myDir, fname);
try
{
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
我尝试了上面的代码,我能够保存背景,但我无法保存绘制的。