gpt4 book ai didi

java - ARCore:如何在表面上显示设备保存的图像

转载 作者:行者123 更新时间:2023-11-30 10:14:34 29 4
gpt4 key购买 nike

我是 AR 的新手。我想知道是否有一种方法可以使用 ARCore for android 将保存在手机上的图片显示到表面上。就像我能够将 Sceneform 示例与预编码图像一起使用,但现在我想将图片文件夹中的照片显示到表面上。我阅读了有关纹理的信息,但我也不确定它是如何工作的。感谢您的提示。

编辑:所以我创建了一个类,用户可以从中选择我通过 Uri 保存的图像

public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);
if (resultCode == this.RESULT_CANCELED) {
return;
}
if (requestCode == GALLERY) {
if (data != null) {
contentURI = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), contentURI);
String path = saveImage(bitmap);
Toast.makeText(imageSelector.this, "Image Saved!", Toast.LENGTH_SHORT).show();

//set the image selected to bitmap so that imageView can display it
imageview.setImageBitmap(bitmap);

Intent intent = new Intent(this, HelloSceneformActivity.class);
intent.putExtra("imageUri", contentURI.toString());
startActivity(intent);

从 ARclass 方面我调用了 Intent 并按如下方式解析它

//start the intent for the image chosen from the library
Bundle extras = getIntent().getExtras();
Uri myUri = Uri.parse(extras.getString("imageUri"));

// When you build a Renderable, Sceneform loads its resources in the background while returning
// a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
ModelRenderable.builder()
.setSource(this, myUri)
.build()
.thenAccept(renderable -> andyRenderable = renderable)
.exceptionally(
throwable -> {
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
});

我可以选择图片,但是程序崩溃了,我得到了这个错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.ar.sceneform.samples.hellosceneform/com.google.ar.sceneform.samples.hellosceneform.HelloSceneformActivity}: java.lang.IllegalArgumentException: Unable to parse url: 'content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F460/ORIGINAL/NONE/1926270799'

Caused by: java.lang.IllegalArgumentException: Unable to parse url: 'content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F460/ORIGINAL/NONE/1926270799'
at com.google.ar.sceneform.utilities.LoadHelper.remoteUriToInputStreamCreator(Unknown Source:56)
at com.google.ar.sceneform.utilities.LoadHelper.fromUri(Unknown Source:40)
at com.google.ar.sceneform.rendering.Renderable$Builder.build(Renderable.java:343)
at com.google.ar.sceneform.rendering.ModelRenderable$Builder.build(ModelRenderable.java:44)
at com.google.ar.sceneform.samples.hellosceneform.HelloSceneformActivity.onCreate(HelloSceneformActivity.java:92)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)

最佳答案

根据 https://github.com/google-ar/sceneform-android-sdk/issues/79您目前无法从自定义 URI 加载:

in 1.0 we interpret all file:// uris as being relative to the assets folder which is why we fail to load from external storage. Consequently, in order to load a Texture from a Uri, you'll need to either put in in the assets folder (i.e. bundled into your apk), or host it online where it's available via an http:// scheme.

这意味着目前仅支持 http://和 file://URI,后者只能与 Assets 文件夹相关。 malik-at-work 在 https://github.com/google-ar/sceneform-android-sdk/issues/64 上的回答证实了这一点:

The URI based file loading isn't looking at external storage. Right now it's only looking for application assets using file:// and remote uris starting with http://

编辑:我建议的解决方法是使用 ViewRenderable结合内部有单个 ImageView 的布局。 ViewRenderable 可以在场景中创建 2D 布局,您只需像在通常的 Android 应用程序中一样将图像设置到 ImageView 中,然后根据自己的喜好定位/旋转生成的对象。您可以在 solarsystem-Sceneform-example 中找到 ViewRenderable 的示例用法。 ,速度 slider 是用它实现的。

编辑 2:这似乎已在 Sceneform 1.4 中修复,因为第一个提到的问题现已关闭。

关于java - ARCore:如何在表面上显示设备保存的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50842189/

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