How to capture image of any layout in background
I want to send graphs in email. So for that I have captured bitmap of that graph and save it in sdcard as image. that works successfully
private Bitmap TakeImage(View v) {
Bitmap screen = null;
try {
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.开发者_StackOverflow社区makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
screen = v.getDrawingCache();
v.setDrawingCacheEnabled(false); // clear drawing cache
} catch (Exception e) {
e.printStackTrace();
}
return screen;
}
But now I want to capture that in background without showing that layout, without notify by user. My previous code does not work for that.
Inflate the view using LayoutInflater
, populate the values and pass it on to the same takeImage(View v)
method.
I'm not sure, and I've not tried, don't know whether this works or not. but give it a try.
Have you tried changing v.getMeasuredWidth(), v.getMeasuredHeight()
to whatever values you desire?
can you use
view.getLocationOnScreen(l);
精彩评论