簡體   English   中英

在不打開圖庫意圖的情況下以Oncreate方法顯示圖庫圖像

[英]Displaying image from gallery in Oncreate method without opening gallery intent

我知道如何打開圖庫意圖並在imageview中顯示。

但是我遇到了在oncreate方法中自動選擇圖像並顯示在imageview中的問題。

我在圖庫文件夾中有一個名為“ myfile.jpg”的圖像

誰能指導我如何做到這一點而無需打開畫廊的意圖。

先感謝您

這是解決方案:

ImageView image = (ImageView)findViewById(R.id.myImage);

File root = Environment.getExternalStorageDirectory();
String path = root.getAbsolutePath();
path = path + File.separator + "myfile.jpg"; //where you image file located

Bitmap myBitmap = BitmapFactory.decodeFile(path);

image.setImageBitmap(myBitmap);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM