捕捉屏幕截图在Android上使用Java code [英] Capture Screen shot on Android using Java code

查看:293
本文介绍了捕捉屏幕截图在Android上使用Java code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  截图Android的

我想捕捉截图编程(不是屏幕截图我的观点),并创建了一个应用程序采取屏幕截图我的看法。

I would like to capture screenshots programatically (not the screen shot of my view) and have created an application to take the screen shot of my view.

我试图捕捉设备的屏幕快照(比如,如果用户opned任何图像文件)通过使用Java code(我想创建服务,并从服务中,我们可以拍照,但我不知道如何实现这一目标)。

I am trying to capture the device screen shot (like if user opned any image file) by using Java code(I thought of creating service and from service we can take picture but I am not sure how to achieve this).

我发现了一些本土code。使用帧缓冲FB0,但我很明白这个,也不知道如何使用它。

I found some native code using frame buffer fb0 but I am very knew to this and no idea how to use it.

推荐答案

下面是一个解决方案,把你的屏幕截图,并把它写入SD卡

Here is a solution to take the screenshot of your screen and write it to the sd card

设置根布局:

View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);

函数来获取渲染视图:

Function to get the rendered view:

private void getScreen()
{
    View content = findViewById(R.id.layoutroot);
    Bitmap bitmap = content.getDrawingCache();
    File file = new File( Environment.getExternalStorageDirectory() + "/test.png");
    try 
    {
        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}

记住要添加

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

您AndroidManifest。

to your AndroidManifest.

这篇关于捕捉屏幕截图在Android上使用Java code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆