从资产文件夹中检索图像?

时间:2014-03-18 08:16:25

标签: android

在活动类我做了这个编码...我在assets / folder1 / hello.png,hi.png,love.png..i中有几个图像想要检索每个图像文件的路径??

final String ASSETS_URI ="file:///android_asset";
final String[] IMAGE_IDS =new String[] {ASSETS_URI+"/"+"one.png",ASSETS_URI+"/"+"two.png",ASSETS_URI+"/"+"three.png"};

iv=(ImageView)findViewById(R.id.iv);
if(i>=0 & i< IMAGE_IDS.length-1)
   i=i+1;
else if(i==IMAGE_IDS.length-1)
   i=0;

iv.setImageURI(Uri.parse(IMAGE_IDS[i]));

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

       AssetManager manager = getAssets();

        try {
            InputStream open = manager.open("one.png");
            Bitmap bitmap = BitmapFactory.decodeStream(open);
            // Assign the bitmap to an ImageView in this layout
            ImageView view = (ImageView) findViewById(R.id.ImageView01);
            view.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }