【问题标题】:Display image using ImageView in ARCore在 ARCore 中使用 ImageView 显示图像
【发布时间】:2019-01-28 14:40:51
【问题描述】:

我正在尝试在 ARCore 中显示 2D PNG 图像,但没有显示任何内容。 当我尝试使用 ModelRenderable 进行渲染时,3D 对象的渲染效果很好。因此,在尝试使用 ViewRenderable 渲染图像时,我做错了。

这里是与渲染有关的代码:在下面的代码中,我收到错误/警告,'imageView' is never used.

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

这是 XML 文件:

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

【问题讨论】:

    标签: android imageview arcore


    【解决方案1】:

    example code 使用:

    .thenAccept(renderable -> testViewRenderable = renderable);
    

    这与您的略有不同,因为您添加了一个 lambda。

    您可能希望删除此 lambda,结果为:

    .thenAccept(renderable -> myRenderable = renderable);
    

    您还需要定义您的myRenderable(不是ImageView):

    the docs 中有一个最小示例。

    【讨论】:

    • 效果很好,谢谢。但是,如果我希望从 URI 获取图像,上述方法将不起作用,因为据我所知,我无法从 URI 将图像加载到 XML 文件中。您对实现这一目标有什么建议吗?
    • 嘿,我建议你问一个新问题!其实我自己没有用过,我只是发现了错字:)
    猜你喜欢
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 2015-11-09
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多