简体   繁体   English

拍摄Android当前视图的屏幕截图

[英]Take Screenshot of the current view in Android

I'm very new to Android. 我是Android的新手。 And I have created a system overlay (similar to Facebook chat heads). 我创建了一个系统覆盖图(类似于Facebook聊天头)。 Now I want to take the screen shot of the current view (where the system overlay is present) progrmatically. 现在,我要以编程方式拍摄当前视图(存在系统覆盖图)的屏幕快照。 System overlay can be in top of any activity, my goal is get the screenshot of any activity. 系统覆盖可以位于任何活动的顶部,我的目标是获取任何活动的屏幕截图。

Is it possible to do so? 有可能这样做吗?

Thanks in advance. 提前致谢。

Is it possible to do so? 有可能这样做吗?

No. You can't get a screenshot of any other app's Activity programmatically. 否。您无法以编程方式获取任何其他应用的“活动”的屏幕截图。

The only thing you can get from this is the overlay itself. 您只能从中获得叠加层本身。
You can easily try it with this method, save the bitmap to storage, and then display it with your gallery app. 您可以使用此方法轻松尝试,将位图保存到存储中,然后在图库应用程序中显示它。
You will only see the overlay content, but nothing below. 您将只看到叠加层内容,但下面没有任何内容。

    public static Bitmap createBitmapFromView(View v) {
        Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        v.draw(canvas);
        return bitmap;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM