为何android4.1 在打开camera照相界面下不能截屏呢?
mScreenBitmap = Surface.screenshot((int) dims[0], (int) dims[1]);
if (mScreenBitmap == null) {
notifyScreenshotError(mContext, mNotificationManager);
finisher.run();
return;
}
mScreenBitmap 打印出来的LOG 是null,继续跟踪screenshot发现在android_view_Surface.cpp文件中的
static jobject doScreenshot(JNIEnv* env, jobject clazz, jint width, jint height,
jint minLayer, jint maxLayer, bool allLayers)
{
ScreenshotPixelRef* pixels = new ScreenshotPixelRef(NULL);
if (!pixels)
return 0;
if (pixels->update(width, height, minLayer, maxLayer, allLayers) != NO_ERROR) {
delete pixels;
return 0;
}
uint32_t w = pixels->getWidth();
uint32_t h = pixels->getHeight();
uint32_t s = pixels->getStride();
uint32_t f = pixels->getFormat();
ssize_t bpr = s * android::bytesPerPixel(f);
SkBitmap* bitmap = new SkBitmap();
if (!bitmap)
return 0;
bitmap->setConfig(convertPixelFormat(f), w, h, bpr);
if (f == PIXEL_FORMAT_RGBX_8888) {
bitmap->setIsOpaque(true);
}
if (w > 0 && h > 0) {
bitmap->setPixelRef(pixels)->unref();
bitmap->lockPixels();
} else {
// be safe with an empty bitmap.
delete pixels;
bitmap->setPixels(NULL);
}
return GraphicsJNI::createBitmap(env, bitmap, false, NULL);
求解啊!!!!!!
------解决方案--------------------
问题找到了。从出现问题的doScreenshot函数里慢慢添加LOG跟踪,最终会跟到SurfaceFlinger.cpp文件的SurfaceFlinger::captureScreen里,注意到:
// if we have secure windows, never allow the screen capture
if (flinger->mSecureFrameBuffer)
return true;
result = flinger->captureScreenImplLocked(dpy,
heap, w, h, f, sw, sh, minLayerZ, maxLayerZ);
Camera打开时,flinger->mSecureFrameBuffer为true,直接return也就不截图了。Camera打开时系统会当成secure windows,请问secure windows啥意思?怎么理解呢?