Bhavik Shah
Bhavik Shah

Reputation: 95

Display image using ImageView in ARCore

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"/>

Upvotes: 2

Views: 1170

Answers (1)

Jake Lee
Jake Lee

Reputation: 7989

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.

Upvotes: 2

Related Questions