How to display a 360 panorama from android application

两盒软妹~` 提交于 2020-01-23 07:38:34

问题


I want to display a panorama from my android application, this panorama is online and I have its url I load it on a webview but it won't work properly. It just appears a portion of it, and it won't turn or move upside down. I have no idea where to start with this, can you point me at the right direction? thank you in advance


回答1:


After a lot of research I found out this library it is still pretty new but sure can help you start with something. I'm posting it just to save time for other searchers! cheers PanoramaGl




回答2:


  1. Add dependency in gradle (app-level)

    compile 'com.google.vr:sdk-panowidget:1.80.0'

  2. Add VrPanoramaView in your xml and get a reference via findViewById() method in android

  3. Below is the code for loading the image from asset.

VrPanoramaView takes input as Bitmap so we need to first convert it into right format. Here, the loadPhotoSphere functions in called in onCreate()

private void loadPhotoSphere() {
  VrPanoramaView.Options options = new VrPanoramaView.Options();
  InputStream inputStream = null;

  try {
      inputStream = assetManager.open("image.jpg");
      options.inputType = VrPanoramaView.Options.TYPE_MONO;
      mVRPanoramaView.loadImageFromBitmap(BitmapFactory.decodeStream(inputStream), options);
      inputStream.close();
  } catch (Exception e) {
      e.printStackTrace();
  }
}

Read about Google VR SDK for Android here




回答3:


I had a similar situation in Kotlin, but I needed to get the image from a URL. I resolved it using Picasso. I leave this here for future reference:

    val options = VrPanoramaView.Options()
    val url = "https://urltoyourimage.com/image.jpg"

    Picasso.get().load(url)
        .into(object : Target {
            override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
                options.inputType = VrPanoramaView.Options.TYPE_MONO
                vrPanoramaView.loadImageFromBitmap(bitmap, options)
            }

            override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
                print(e?.localizedMessage)
            }

            override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
                print(placeHolderDrawable)
            }
    })


来源:https://stackoverflow.com/questions/20612058/how-to-display-a-360-panorama-from-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!