以活动的截图编程截图

2023-09-12 05:21:34 作者:死一樣的痛过

我的要求是采取截屏活动,并分享社交网站。

My requirement is to take the screen shot of an activity and share in social networking sites.

我的问题是,该活动包含一个可滚动视图(自定义的FrameLayout),我需要得到完整的滚动视图的快照(滚动视图尺寸大于屏幕边界大)。

My problem is that, the activity contains a scrollable view (custom FrameLayout), and I need to get the image of the complete scrollview in snapshot(scrollview size is larger than screen bounds).

(这实际上是由延伸框架布局作出了定制视图,滚动diagonally.I需要显示树状结构由节点和连接在该链接。树结构的高度和宽度可以比屏幕大界。我需要这整个树结构的卡店与大家共享。这正是我的要求是什么。)

(This is actually a custom view made by extending Frame layout, to scroll diagonally.I need to display a tree like structure consisting of nodes and connecting links in that. The height and width of the tree structure can be larger than screen bounds. I need to take snap shop of this whole tree structure and share. This is exactly what my requirement is.)

请指点我如何做到这一点。谢谢。

Please advice me how to do this. Thanks.

推荐答案

试试下面的。

传递滚动视图连同的宽度和高度作为参数去下面的功能。它会返回一个位图可用于共享社交网站

Pass the scroll view along with the width and height as a param to the below function. It will return a bitmap which can be used to share on social networking sites

public static Bitmap loadBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);                
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}