Android gallery setting image from assest folder
I want to set images of my gallery using files i开发者_如何学运维n assest folder.
Try the following with an assets folder such as /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);
Just also thought, if your using GalleryView, and have a dataprovider then you might be able to format the image paths using
file://mnt/sdcard/imageassets/
I think there is also a way to access your apk assets folder, using a URI path, similar to
"android.resource://[package]/[res id]"
This explains it well.
http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html
精彩评论