繁体   English   中英

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

[英]Android gallery setting image from assest folder

我想使用assest文件夹中的文件设置画廊的图像。

尝试使用资产文件夹(例如/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 / sdcard / imageassets /

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

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

这很好地解释了。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM