2

I am trying to display a 2D PNG image in ARCore, but nothing is being displayed. The rendering of a 3D object works perfectly when I try to render using ModelRenderable. So there is something I am doing wrong when trying to render an image using ViewRenderable.

Here is the code pertaining to the rendering: In the below code, I get the error/warning, 'imageView' is never used.

ViewRenderable.builder()
                      .setView(context, R.layout.imgboard)
                      .build()
                      .thenAccept(renderable -> {
                      ImageView imageView = (ImageView) renderable.getView();
                      });

Here is the XML file:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imageCard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/qbf"
    android:adjustViewBounds="true"
    android:scaleType="centerInside"/>
Zoe
  • 27,060
  • 21
  • 118
  • 148
Bhavik Shah
  • 95
  • 1
  • 11

1 Answers1

2

The example code uses:

.thenAccept(renderable -> testViewRenderable = renderable);

which is slightly different to yours, as you've added a lambda.

You likely want to remove this lambda, ending up with:

.thenAccept(renderable -> myRenderable = renderable);

You'll also need to define your myRenderable (which isn't an ImageView):

There's a minimal example in the docs.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
  • That works perfectly, thank you. However, if I wish to fetch the image from a URI, the above method would not work, as I cannot load an image into the XML file from a URI as far as I know. Would you have any suggestions for achieving that? – Bhavik Shah Jan 28 '19 at 17:58
  • Hey, I suggest you ask a new question bud! I actually haven't used it myself, I just spotted the typo :) – Jake Lee Jan 28 '19 at 18:29