在我的应用程序中我想要捕获具有surfaceview的屏幕但我无法捕获使用background.how绘制的屏幕以保存屏幕与background一起绘制。请帮助我如何解决此问题。< / p>
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();
}
}
我尝试了上面的代码我能够保存背景,但我无法保存所绘制的。
答案 0 :(得分:2)
public static Bitmap overlay(Bitmap bmp1,Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0,0, null);
canvas.drawBitmap(bmp2, 0, 0, null);
Log.i("bmOverlay.......",""+bmOverlay);
bmp3=bmOverlay;
return bmOverlay;
}
private void getScreen() {
Toast.makeText(BookType1.this, "saved", Toast.LENGTH_SHORT).show();
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);
bmp3.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
通过重叠两个位图,我在一个位图中解决了这个问题,我捕获了背景,在第二个位图中我捕获了表面视图,并且我在这个问题上重叠了两个。