2017-04-06 46 views
-2

基于VR查看示例代码教程,如何从url或数据库获取全景图像?vr查看android,如何从URL获得图像

由于示例教程是加载默认图像加载资产管理器,我想知道如何从互联网/ URL图像链接加载它。

我在这里的第一个活动

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_detail_kuliner); 

    //INITIALIZE VIEWS 
    nama_kul = (TextView) findViewById(R.id.nameDetail_kul); 
    lokasi_kul = (TextView) findViewById(R.id.lokasi_kul); 
    desclong_kul = (TextView) findViewById(R.id.desclong_kul); 
    image_kul = (ImageView) findViewById(R.id.imageDetail_kul); 

    //RECEIVE DATA 
    Intent intent=this.getIntent(); 
    String name_kul=intent.getExtras().getString("NAME_KEY"); 
    String lokas_kul=intent.getExtras().getString("LOKASI_KEY"); 
    final String descshor_kul=intent.getExtras().getString("DESCSHORT_KEY"); 
    String desclon_kul=intent.getExtras().getString("DESCLONG_KEY"); 
    final String images_kul=intent.getExtras().getString("IMAGE_KEY"); 

    //BIND DATA 
    nama_kul.setText(name_kul); 
    lokasi_kul.setText(lokas_kul); 
    desclong_kul.setText(desclon_kul); 
    Glide.with(this).load(images_kul).into(image_kul); 

    //Intent to 2nd activity 
    detail2ButtonStart = (ImageButton) findViewById(R.id.detail2_but); 
    detail2ButtonStart.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(detail_kuliner.this, detail2_kuliner.class); 
      intent.putExtra("DESCSHORT2_KEY",descshor_kul); 
      intent.putExtra("IMAGE2_KEY",images_kul); 

      //open activity 
      startActivity(intent); 
     } 
    }); 

,这是我的第二个活动

public class detail2_kuliner extends AppCompatActivity { 

private static final String TAG = detail2_kuliner.class.getSimpleName(); 
private VrPanoramaView panoWidgetView; 
public boolean loadImageSuccessful; 
private Uri fileUri; 
private Options panoOptions = new Options(); 
private ImageLoaderTask backgroundImageLoaderTask; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_detail2_kuliner); 
    panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view); 
    panoWidgetView.setEventListener(new ActivityEventListener()); 
    handleIntent(getIntent()); 
} 

@Override 
protected void onNewIntent(Intent intent) { 
    Log.i(TAG, this.hashCode() + ".onNewIntent()"); 
    setIntent(intent); 
    handleIntent(intent); 
} 

private void handleIntent(Intent intent) { 
    if (Intent.ACTION_VIEW.equals(intent.getAction())) { 
     Log.i(TAG, "ACTION_VIEW Intent recieved"); 

     fileUri = intent.getData(); 
     if (fileUri == null) { 
      Log.w(TAG, "No data uri specified. Use \"-d /path/filename\"."); 
     } else { 
      Log.i(TAG, "Using file " + fileUri.toString()); 
     } 

     panoOptions.inputType = intent.getIntExtra("inputType", Options.TYPE_MONO); 
     Log.i(TAG, "Options.inputType = " + panoOptions.inputType); 
    } else { 
     Log.i(TAG, "Intent is not ACTION_VIEW. Using default pano image."); 
     fileUri = null; 
     panoOptions.inputType = Options.TYPE_MONO; 
    } 

    if (backgroundImageLoaderTask != null) { 
     backgroundImageLoaderTask.cancel(true); 
    } 
    backgroundImageLoaderTask = new ImageLoaderTask(); 
    backgroundImageLoaderTask.execute(Pair.create(fileUri, panoOptions)); 
} 

@Override 
protected void onPause() { 
    panoWidgetView.pauseRendering(); 
    super.onPause(); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    panoWidgetView.resumeRendering(); 
} 

@Override 
protected void onDestroy() { 
    panoWidgetView.shutdown(); 

    if (backgroundImageLoaderTask != null) { 
     backgroundImageLoaderTask.cancel(true); 
    } 
    super.onDestroy(); 
} 

class ImageLoaderTask extends AsyncTask<Pair<Uri, Options>, Void, Boolean> { 

    @Override 
    protected Boolean doInBackground(Pair<Uri, Options>... fileInformation) { 
     Options panoOptions = null; 
     InputStream istr = null; 
     if (fileInformation == null || fileInformation.length < 1 
       || fileInformation[0] == null || fileInformation[0].first == null) { 
      AssetManager assetManager = getAssets(); 

      try { 
       istr = new URL("http://SOME URL IMAGE").openStream(); //How to get SOME URL IMAGE from intent sent at first activity 

       panoOptions = new Options(); 
       panoOptions.inputType = Options.TYPE_STEREO_OVER_UNDER; 
      } catch (IOException e) { 
       Log.e(TAG, "Could not decode default bitmap: " + e); 
       return false; 
      } 
     } else { 
      try { 
       istr = new FileInputStream(new File(fileInformation[0].first.getPath())); 
       panoOptions = fileInformation[0].second; 
      } catch (IOException e) { 
       Log.e(TAG, "Could not load file: " + e); 
       return false; 
      } 
     } 
    panoWidgetView.loadImageFromBitmap(BitmapFactory.decodeStream(istr), panoOptions); 
     try { 
      istr.close(); 
     } catch (IOException e) { 
      Log.e(TAG, "Could not close input stream: " + e); 
     } 
     return true; 
    } 
} 

}

,所以我想用与附带的数据加上VR查看到第二活动的意图,数据是从数据库发送的JSON格式,基于本教程VR View for android我可以把数据的意图从第一个活动到第二个活动(一些网址图片)?

感谢你的帮助

+0

欢迎来到Stackoverflow!要获得有帮助的答案,请包括迄今尝试解决此问题的代码或步骤,以便我们可以帮助您进行调试或改进。 – ITWitch

回答

0

您可以使用毕加索,滑行或ImageLoader的:下面的例子:

Picasso.with(mContext) 
.load("yoururl") 
.config(Bitmap.Config.RGB_565) 
.error(R.drawable.blank) 
.centerInside() 
.into(imageView); 
+0

我明白了,我有意在之前的另一项活动中传递jason数组的数据,因此我可以将意图内的数据(url图像链接)传递给下一个显示VR视图框架 –

0

其实你无法从服务器获取现场,首先你需要从投放到下载您的项目,然后使用它在SD卡或内部folder.thanks保存该图像的位置。谢谢。

+0

的活动吗?我该怎么做,谢谢 –