如何使用ScreenShotClient在我的Android应用程序(How to use Scre

2019-07-31 21:01发布

我开发一个应用程序,它可以帮助用户捕捉到的Android屏幕截图(安卓4.x版)。 我知道帧缓冲区在Android ICS打破。 我听说,我们可以使用ScreenShotClient到如下做到这一点。

ScreenshotClient screenshotClient = new ScreenshotClient();
screenshotClient->update();

但是,什么库我已经导入使用它? 它是可用下JNI代码使用?

Answer 1:

您所需要的库称为libsurfaceflinger_client.so。 您可以从运行姜饼 Android的版本的任何设备拉,用命令

adb pull /system/lib/libsurfaceflinger_client.so

在ICS或JB,类ScreenshotClient是部分libgui.so 。 为撷取画面生成文件作为使用ScreenshotClient的例子中,表明,接头可能需要的其它库:

libcutils libutils libbinder libskia libui libgui

而且,代码screencap.cpp去如下:

ScreenshotClient screenshot;
if (screenshot.update() == NO_ERROR) {
    base = screenshot.getPixels();
    w = screenshot.getWidth();
    h = screenshot.getHeight();
    f = screenshot.getFormat();
    size = screenshot.getSize();
} else {
    const char* fbpath = "/dev/graphics/fb0";
    int fb = open(fbpath, O_RDONLY);
    if (fb >= 0) {
        struct fb_var_screeninfo vinfo;
        if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) == 0) {
...

这意味着,至少你必须检查更新()成功。 不幸的是,除非德装置扎根,该应用无法获准从读取/dev/graphics/fb0和使用的后退/system/bin/screencap/system/bin/screenshot



文章来源: How to use ScreenShotClient in my android application