atfeel
V2EX  ›  Android

Android 的 shell screencap -p 太慢了,有没有更高效的方法呢?

  •  
  •   atfeel · Apr 28, 2020 · 14734 views
    This topic created in 2209 days ago, the information mentioned may be changed or developed.

    各位 V 友,下面是我截屏的代码

    Process process = Runtime.getRuntime().exec("su");

    OutputStreamWriter outputStream = new OutputStreamWriter(process.getOutputStream());

    outputStream.write("/system/bin/screencap -p\n");

    outputStream.flush();

    Bitmap bitmap = BitmapFactory.decodeStream(process.getInputStream());

    outputStream.write("exit\n");

    outputStream.flush();

    outputStream.close();

    执行这个代码能获得 bitmap 图像信息,但是这个代码很慢,如果手机再运行点其他的 APP 耗时会更多 1000ms-6000ms 左右,根本没法用了。

    大家有什么好方法能替代这种方式吗?

    要是能在运行其他耗资源的 APP 的同时控制截屏耗时在 300ms-1000ms 以内。 那真的是个很跨越的突破。

    Supplement 1  ·  Apr 28, 2020
    我指的是屏幕截图,不是 APP view 的界面
    13 replies    2020-04-30 10:14:13 +08:00
    bage2020
        1
    bage2020  
       Apr 28, 2020
    研究一下系统自己的截屏方法,framwork 反射试试
    Anarchy
        2
    Anarchy  
       Apr 28, 2020
    我提一个思路吧:获取当前焦点 activity,然后获取 window,获取 decorView,再转换成 bitmap 。
    atfeel
        3
    atfeel  
    OP
       Apr 28, 2020
    @Anarchy 我要截屏不是当前 app 的界面,是屏幕截图
    hoholiday
        4
    hoholiday  
       Apr 28, 2020 via Android
    mediaprojection 了解一下
    jemyzhang
        5
    jemyzhang  
       Apr 28, 2020
    @atfeel #3 是领导要求你后台偷偷截屏吗?
    曾经某大电视大厂领导开大会时就说,我们要统计用户行为,有什么好办法呢,截屏传到服务器解析,喷了喷了
    300
        6
    300  
       Apr 28, 2020
    https://github.com/Genymobile/scrcpy

    不知道这个是怎么实现的
    atfeel
        7
    atfeel  
    OP
       Apr 29, 2020
    @hoholiday mediaprojection 的话,会出现录制的确认框,不友好
    atfeel
        8
    atfeel  
    OP
       Apr 29, 2020   ❤️ 1
    @winterbells 这个和 screencap 一样,都是 C+开发的程序,这些是很资深的高手才能做到,涉及面太广了
    mrcn
        9
    mrcn  
       Apr 29, 2020 via Android   ❤️ 1
    @winterbells #6 他在手机上有服务程序的,再通过 tcp 传数据到电脑上
    300
        10
    300  
       Apr 29, 2020
    @mrcn #9 哦哦,原来是传 jar 包,我因为是什么 shell 里的 api
    Clay0620
        11
    Clay0620  
       Apr 29, 2020
    STF 框架的 minicap 试一下?和 scrcpy 原理应该差不多,都是把屏幕以流的形式,发送到一个指定的端口,你需要把流转换成图片
    huage2580
        12
    huage2580  
       Apr 30, 2020
    这个,你是 ROM 定制的 APP 是吗,Rom api 21 以上,VirtualDisplay 省事。
    不然就反射 SurfaceControl,要有 shell 以上权限,我看你都有 su 权限了。
    atfeel
        13
    atfeel  
    OP
       Apr 30, 2020
    @CY4suncheng minicap 条件不好,CPU,SDK,版本都会影响,
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2830 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 15:26 · PVG 23:26 · LAX 08:26 · JFK 11:26
    ♥ Do have faith in what you're doing.