Android画廊设置图像来自assets文件夹

时间:2011-01-07 10:01:28

标签: android gallery

我想使用assets文件夹中的文件设置我的图库的图像。

1 个答案:

答案 0 :(得分: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);

还想到,如果您使用GalleryView,并且有数据提供者,那么您可以使用

格式化图像路径

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

我认为还有一种使用URI路径访问apk资源文件夹的方法,类似于

“android.resource:// [package] / [res id]”

这很好地解释了。

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

相关问题