相关疑难解决方法(0)

如何以编程方式截取屏幕截图?

如何通过任何程序而不是代码来截取手机屏幕的选定区域?

android screenshot

483
推荐指数
19
解决办法
31万
查看次数

Android以编程方式拍摄屏幕截图

首先,我正在编写一个根应用程序,因此root权限不成问题.我搜索过并搜索过,发现很多代码对我来说从来没有用过,这是我到目前为止拼凑起来的东西.当我说sorta我的意思是它在我的/sdcard/test.png上生成一个图像但是该文件是0字节,显然无法查看.

public class ScreenShot extends Activity{

View content;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.blank);
    content = findViewById(R.id.blankview);
    getScreen();
}

private void getScreen(){
    Bitmap bitmap = content.getDrawingCache();
    File file = new File("/sdcard/test.png");
    try 
    {
        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

任何有关如何通过代码在Android屏幕截图拍摄的帮助将非常感谢谢谢!

===编辑===

以下是我正在使用的所有图像是在我的SD卡上制作的,不再是0bytes但是整个东西都是黑色的,上面没有任何内容.我已将活动绑定到我的搜索按钮,所以当我在手机上的某个地方时,我长按搜索,它应该拍摄屏幕截图但我只是得到一个黑色图像?一切都设置透明,所以我认为它应该抓住屏幕上的任何东西,但我只是一直变黑

表现

<activity android:name=".extras.ScreenShot"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:noHistory="true" >
    <intent-filter>
        <action android:name="android.intent.action.SEARCH_LONG_PRESS" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android caching screenshot image bitmap

46
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×2

screenshot ×2

bitmap ×1

caching ×1

image ×1