首页 > 解决方案 > 如何在 Android 上使用 ScreenshotClient 获得快速像素颜色?

问题描述

我想使用带有参数 x 和 y 的二进制文件来获取颜色像素。屏幕截图非常慢。使用虚拟显示器也不会产生预期的结果。

我找到并编码screencap和好项目:sji-android-screen-capture-oldsji-android-screen-capture-new

但这些解决方案无法在我的手机中运行。如果在编译get-raw-image.cpp 后运行 get-raw-image.cpp我得到错误:

WARNING: linker: /data/local/tmp/get-raw-image-4.1.2: unused DT entry: type 0xf arg 0x21d
CANNOT LINK EXECUTABLE: cannot locate symbol "_ZN7android16ScreenshotClient6updateERKNS_2spINS_7IBinderEEE".

对于编译,我使用以下设置:

/root/arm/bin/arm-linux-androideabi-clang -pie get-raw-image.cpp -lsupc++ libgui.so -o /get-raw-image-4.1.2 -Xlinker -rpath=/system/lib -DTARGET_JB

如果运行Android-fast-screen-capture

/root/arm/bin/arm-linux-androideabi-clang -pie /screen/ascreencap.cpp -o /test -std=c++11

我有错误:

In file included from /screen/ascreencap.cpp:8:
In file included from /root/arm/bin/../sysroot/usr/include/binder/IPCThreadState.h:21:
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:86:11: error: unknown type
      name 'binder_size_t'
    const binder_size_t* objects() const;
          ^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:220:47: error: unknown type
      name 'binder_size_t'
                                        const binder_size_t* objects, si...
                                              ^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:228:51: error: unknown type
      name 'binder_size_t'
                                            const binder_size_t* objects...
                                                  ^
/root/arm/bin/../sysroot/usr/include/binder/Parcel.h:264:5: error: unknown type
      name 'binder_size_t'
    binder_size_t*      mObjects;
    ^
In file included from /screen/ascreencap.cpp:8:
/root/arm/bin/../sysroot/usr/include/binder/IPCThreadState.h:114:50: error:
      unknown type name 'binder_size_t'
                                           const binder_size_t* objects...
                                                 ^
5 errors generated.

我还发现了问题how-to-use-screenshotclient-in-my-android-application但我不明白如何设置到 ScreenshotClient 的链接,以便编译器不会返回错误。

我的手机是 Homtom HT16:

Processor   : ARMv7 Processor rev 3 (v7l)
processor   : 0
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 26.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm

也许有人会告诉你如何在我的手机下编译代码或者解决问题的方法。

标签: androidgccarmscreen-capturenative-code

解决方案


我解决了我的问题。

脚步:

1) 从安卓手机复制需求库(libgui.so, libui.so, libcutils.so, libutils.so, libbinder.so)。

2) 添加 sys_root (当从 Android Android 6_r1 libs保存 ndk lib 代码文件时:) utils, cutils, system, log, hardware, system, ports, core, include/gui, include/ui, include/binder。您可以运行此代码来查找您的系统根目录:

echo "#include <bogus.h> int main(){}" > t.c; GCC_OR_CLANG_BINARY_LINK -v t.c; rm t.c

错误打印了编译器搜索包含文件的所有路径。或--sysroot=YOUR_PATH用于设置您的路径。

-Wl,--unresolved-symbols=ignore-all3)为忽略错误和--target=armv7-none-linux-androideabi23(23或其他)设置目标版本添加标志。

填写我的clang命令:

/Users/macbookair/Documents/test/bin/clang -fPIE -pie fast-screen-capture.cpp *.so -o ./screencap --target=armv7-none-linux-androideabi23 -Wl,--unresolved-symbols=ignore-all -s

成功!


推荐阅读