如何将一个活动转换为一张图片

3

我有一个包含多个视图的活动,在进行一些操作后,我想将此活动的外观转换为图像并通过电子邮件发送。我可以发送图像,但是如何将该活动转换为图像呢?这是否可能?


1
尝试使用SO - https://dev59.com/83A75IYBdhLWcg3w3M9e - karakuricoder
2个回答

2
你可以通过编程的方式对设备进行屏幕截图,这应该能起到作用。查看这个SO答案,它应该能帮助你入门。

0

您可以通过捕获绘图缓存,将应用程序的不同视图呈现为位图对象。

有关更多详细信息,请参见http://blog.neurolive.net/2010/11/385/。 (感谢出色的教程)

特别是

private Bitmap getScreenViewBitmap(View v) {
    v.setDrawingCacheEnabled(true);

    // this is the important code :)  
    // Without it the view will have a dimension of 0,0 and the bitmap will be null          
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 

    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache
}

看起来这是你感兴趣的内容。(只需找到你的顶级视图并使用此方法捕获位图)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接