0
我想使用android源代碼捕捉android4.0.3中的屏幕。它可以正確編譯。運行時,它有錯誤:Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1).
調試發現在cpp文件中調用composer->captureScreen
函數,然後返回NO_ERROR值,但heap爲null,w和h爲0.所以在調用heap-> getBase()時出現錯誤。 。我對此感到困惑。關於Android作曲家 - > captureScreen捕捉屏幕
{
const char *file_path = env->GetStringUTFChars(file, NULL);
const String16 name("SurfaceFlinger");
sp<ISurfaceComposer> composer;
getService(name, &composer);
sp<IMemoryHeap> heap;
uint32_t w, h;
PixelFormat f;
status_t err = composer->captureScreen(0, &heap, &w, &h, &f,0,0,0,INT_MAX);///*for 4.1.3*/,0,0
if (err != NO_ERROR) {
LOGE("screen capture failed: %s\n", strerror(-err));
exit(0);
}
LOGD("screen capture success: w=%u, h=%u, pixels=%p\n",
w, h, heap->getBase());
LOGD("saving file as PNG in %s ...\n", file_path);
SkBitmap b;
b.setConfig(SkBitmap::kARGB_8888_Config, w, h);
b.setPixels(heap->getBase());
SkImageEncoder::EncodeFile(file_path, b,
SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality);
return file;
}
編輯:我在清單中添加
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
。