Java 在另一屏幕元素上设置ARCore Sceneview

Java 在另一屏幕元素上设置ARCore Sceneview,java,android,xml,arcore,sceneform,Java,Android,Xml,Arcore,Sceneform,我试图通过简单地使用一个片段的提要并将另一个屏幕元素设置为相同的方式在屏幕上显示一个arFragment两次,但我无法确定要使用哪个元素 我知道,我通过打电话获取当前的相机图像 ArFragment arFragment = (ArFragment) getSupportFragmentManager() .findFragmentById(R.id.arFragment); Image image = arFragment.getArSce

我试图通过简单地使用一个片段的提要并将另一个屏幕元素设置为相同的方式在屏幕上显示一个arFragment两次,但我无法确定要使用哪个元素

我知道,我通过打电话获取当前的相机图像

ArFragment arFragment = (ArFragment) getSupportFragmentManager()
                           .findFragmentById(R.id.arFragment);
Image image = arFragment.getArSceneView().getArFrame().acquireCameraImage();
但是我不知道如何获取另一个screen对象并将视图设置为提要,arFragment给了我。例如:

TextureView secondView = (TextureView) findViewById(R.id.texture);
secondView.setSurfaceTexture((SurfaceTexture) image);
产生不可转换类型错误

我不能使用另一个arFragment,因为这将有另一个已经分配的摄像头(显然,这会产生一个黑屏和一个“摄像头已在使用”错误)。我还没有找到一份工作

arFrame.assignCamera();
方法,这无关紧要,因为片段使用的摄影机只是一个对象,而不是真实的对象。但我不知道硬件在哪里与碎片绑定。如果我没记错的话,我也不会读也不会写

我可以将提要转换为位图,并将其放置到imageView上,但我有点害怕每秒执行60次。必须有一个简单的解决方案,对吗


两次显示一个视图不会这么难吧-。-

好的,明白了。转换成bmp有点神奇,但我想这真的没有直接的方法

所以我初始化了bytebuffer,分析了android.media.image的YUV组件,将它们转换成Jpeg,然后将其转换成位图,将其旋转90度以匹配原始图片

// get the arFragment
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
ArSceneView arSceneView = arFragment.getArSceneView();

// set up a Listener to trigger on every frame
arSceneView.getScene().addOnUpdateListener(frameTime -> 
{
  try 
  {
   frame = arSceneView.getArFrame();
   androidMediaImage = frame.acquireCameraImage();
   int imageWidth = androidMediaImage.getWidth();
   int imageHeight = androidMediaImage.getHeight();

   // select the target Container to display the image in
   ImageView secondView = (ImageView) findViewById(R.id.imageView3);
   byte[] nv21;

   // an Android.Media.Image is a YUV-Image which is made out of 3 planes
   ByteBuffer yBuffer = androidMediaImage.getPlanes()[0].getBuffer();
   ByteBuffer uBuffer = androidMediaImage.getPlanes()[1].getBuffer();
   ByteBuffer vBuffer = androidMediaImage.getPlanes()[2].getBuffer();

   // set up a Bytearray with the size of all the planes
   int ySize = yBuffer.remaining();
   int uSize = uBuffer.remaining();
   int vSize = vBuffer.remaining();

   nv21 = new byte[ySize + uSize + vSize];

   // Fill in the array. This code is directly taken from https://www.programcreek.com 
   //where it was pointed out that U and V have to be swapped
   yBuffer.get(nv21, 0 , ySize);
   vBuffer.get(nv21, ySize, vSize);
   vBuffer.get(nv21, ySize + vSize, uSize);

   // combine the three layers to one nv21 image
   YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, imageWidth, imageHeight, null);
   // Open a Bytestream to feed the compressor
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   // compress the yuv image to Jpeg. This is important, because the BitmapFactory can't read a 
   // yuv-coded image directly (belief me I tried -.-)
   yuvImage.compressToJpeg(new Rect(0, 0, imageWidth, imageHeight), 50, out);
   // now write down the bytes of the image into an array
   byte[] imageBytes = out.toByteArray();
   // and build the bitmap using the Factory
   Bitmap bitmapImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);

   // use a Matrix for the rotation
   Matrix rotationMatrix = new Matrix();
   // the thing is basically a bunch of numbers which then can be used to compute the new location of each pixel
   rotationMatrix.postRotate(90);
   // the rotatedImage will be our target image
   Bitmap rotatedImage = Bitmap.createBitmap(bitmapImage, 0,0, bitmapImage.getWidth(), bitmapImage.getHeight(), rotationMatrix, true);

   // it's so easy!!!!
   secondView.setImageBitmap(rotatedImage);
  } catch (NotYetAviableException e) 
   {
     e.printStackTrace();
   }
});
如果我完全弄错了,你显然可以纠正我,而且有一种更简单的解决方法。但它至少起作用了,所以我很高兴