Android:使用Native Executable捕获屏幕只返回部分屏幕

时间:2014-06-09 21:54:34

标签: android screen-capture

我使用Android 4.4.2(API 19)并创建了一个Native Executable(使用ADB单独加载),它使用以下代码来抓取帧缓冲区:

std::string theMessage;
android::sp <android::IBinder> display = android::SurfaceComposerClient::getBuiltInDisplay(android::ISurfaceComposer::eDisplayIdMain);
android::ScreenshotClient ssc;
if (ssc.update(display) == android::NO_ERROR) {  // may also use ssc.update(displayID, width, height) to refine different resolutions
    theMessage = s_screenshot;
    theMessage += toStringPadTwo(ssc.getWidth());
    theMessage += toStringPadTwo(ssc.getHeight());
    uint32_t size   = ssc.getSize() ;
    uint8_t* buffer = (uint8_t*)(ssc.getPixels());
    for (int i=0; i<(size); i+=1) {
        theMessage += buffer[i];
    }
    std::cout << "TakeScreenshot returned with WIDTH = " << ssc.getWidth() << " and HEIGHT = " << ssc.getHeight() << std::endl;
    s_sysServerPtr->sendMessage(theMessage);  // return screen capture data to Java app
}
else {
    theMessage = s_fbFailed;
    s_sysServerPtr->sendMessage(theMessage); // return failed response to Java app
}

我在屏幕分辨率为800x1280的Nexus 7触控板上测试此代码。每次调用此代码段都会返回正确的字节数(800 * 1280 * 4)。但是,每个调用仅返回屏幕的一部分,切掉顶部并用黑色像素填充底部剩余部分。

有没有人知道我做错了什么?

0 个答案:

没有答案