I'm trying to save a screenshot of my current Activity, but not the whole view, just part of it. In my case: My activity
At the attached image, i want to save a bitmap constructed from views B,C & D.
B is a linear layout, C is a pure bitmap, and D is a relative layout.
To my understanding, one way to go is creating a canvas, add all 'elements' into it and finally have the custom bitmap desired.
I'm having trouble with the following code:
iViewBHeight= viewB.getHeight();
// Prepare empty bitmap as output
Bitmap result = Bitmap.createBitmap(bitmapC.getWidth(),bitmapC.getHeight() + iViewBHeight, Config.ARGB_8888);
// Flush source image into canvas
Canvas canvas = new Canvas(result);
// Draw bitmap C to canvas 'under' view B
canvas.drawBitmap(bitmapC, 0, iViewBHeight, null);
// Draw view B to canvas
viewB.setDrawingCacheEnabled(true);
viewB.buildDrawingCache(true);
canvas.drawBitmap(Bitmap.createBitmap(viewB.getDrawingCache()), 0, 0, null);
viewB.setDrawingCacheEnabled(false);
// Desired bitmap is at 'result'
The result is that bitmap C is drawn Ok, but view B is too large and extends the bitmap. I didn't try adding view D..
Can anyone help me? Maybe there are better ways achieving my goal? Thanks!