读取assets文件夹中的图片代码

jopen 9年前

先将图片放到assets文件夹下        private Bitmap[] mBitmap = null;    //    //根据文件名读取assets文件夹的图片        private Bitmap getBit(String filename){    //以最省内存的方式读取本地资源的图片          BitmapFactory.Options options = new BitmapFactory.Options();  //        options.inSampleSize = 2;//图片宽高都为原来的二分之一,即图片为原来的四分之一          options.inPreferredConfig = Bitmap.Config.RGB_565;           options.inPurgeable = true;           options.inInputShareable = true;           AssetManager asm = getAssets();          InputStream is;          Bitmap bitmap = null;          try {              is = asm.open(filename);              bitmap = BitmapFactory.decodeStream(is                      , null, options);  //            mImageView.setImageBitmap(bitmap);              is.close();          } catch (IOException e) {              // TODO Auto-generated catch block              e.printStackTrace();          }          return bitmap;        }    //初始化图片容器       private void getbitmap(){          mBitmap = new Bitmap[14];  //        mBitmap[0] = getBit("img1.jpg");                    for(int i=0; i<14; i++){              int b = i+1;              String s = "img"+b+".jpg";              mBitmap[i] = getBit(s);          }      }      // 获取string中的string-array          Resources res = getResources();          String [] arr = res.getStringArray(R.array.arr_name);