在ARCore中,创建了VirtualDisplay并传入第二个附加参数Surface(“Augmented”),将App透明ACTIVITY显示在此Surface上,将产生绿色背景,即绿屏。要解决ARCore绿屏问题,可以通过以下代码示例进行:
// 获取场景的宽高。
int screenWidth = getResources().getDisplayMetrics().widthPixels;
int screenHeight = getResources().getDisplayMetrics().heightPixels;
// 创建MediaProjectionManager.
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
// 获取MediaProjection
Intent intent = projectionManager.createScreenCaptureIntent();
startActivityForResult(intent, REQUEST_CODE_CAPTURE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CAPTURE && resultCode == RESULT_OK) {
// 获取MediaProjection.
MediaProjection mediaProjection = projectionManager.getMediaProjection(resultCode, data);
// 创建VirtualDisplay.
VirtualDisplay virtualDisplay = mediaProjection.createVirtualDisplay("ScreenCapture", screenWidth, screenHeight,
getResources().getDisplayMetrics().densityDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
// 创建与ARCore场景保持相同尺寸的表面。
augmentedImageDatabase.createNextSurface(new SurfaceTexture(true)), null, null);
}
}
上述代码中,我们创建了一个名为VirtualDisplay的对象,并使用MediaProjection API将ARCore场景成像到该对象上,而不是SurfaceView对象,解决了ARCore绿屏问题。
上一篇:ARCore框架保存
下一篇:ARCore模型大小