gpt4 book ai didi

java - ARCore ArSceneView 捕获位图

转载 作者:行者123 更新时间:2023-12-02 02:21:03 25 4
gpt4 key购买 nike

我正在尝试添加一个屏幕截图按钮,用于捕获 ARCore 相机 View 的屏幕截图,包括附加的节点。

我尝试了几种不同的方法,所有方法都能够捕获屏幕上的其他内容,但 ARSceneView 始终是透明的。

我尝试过的事情:

ArFragment arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
View view = arFragment.getARSceneView(); //Also tried arFragment.getView();

(1)

view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);

(2)

Bitmap bitmap = getBitmapFromView(view);

public Bitmap getBitmapFromView(View view) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
Bitmap returnedBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable drawable = view.getBackground();
if (drawable != null)
drawable.draw(canvas);
view.draw(canvas);
return returnedBitmap;
}

我也知道你可以从ARFragment获取图像,但它返回一个空白的透明图像

Image image = arFragment.getArSceneView().getArFrame().acquireCameraImage();
//image is completely transparent and wrong size

最佳答案

您可以使用 PixelCopy.request()

ArSceneView view = fragment.getArSceneView();
final Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
PixelCopy.request(view, bitmap, (copyResult) -> {
if (copyResult == PixelCopy.SUCCESS) {
// Save bitmap
} else {
// Error
}
}, handler);

Source

关于java - ARCore ArSceneView 捕获位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57275235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com