2011-01-07 56 views

回答

0

如果您使用嘗試圖庫視圖與資產的文件夾下,如/assets/images/myimage.jpg

String imagePath = "images/myimage.jpg" 

Bitmap bmp = null; 
try{ 
    InputStream is = getAssets().open(imagePath);   
    bmp = BitmapFactory.decodeStream(is); 
} 
catch(Exception exception) 
{ 
    bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon_grey_box); 
} 
((ImageView)findViewById(R.id.myimage)).setScaleType(ImageView.ScaleType.CENTER_CROP); 
((ImageView)findViewById(R.id.myimage)).setImageBitmap(bmp); 

剛還認爲,和有一個數據提供程序,那麼你可能能夠將圖像格式使用

文件路徑:// MNT/SD卡/ imageassets/

我覺得還有一種方法來訪問您的APK文件夾的資產,使用URI路徑,類似於

「android.resource:// [package]/[res id]」

這解釋得很好。

http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html

+0

感謝您的啓發 – ingsaurabh 2011-01-10 05:49:27

相關問題