2017-04-06 21 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

的活動嗎?我該怎麼做,謝謝 –