- // 用反射机制来获取资源中的图片ID和尺寸
- Field[] fields = R.drawable.class.getDeclaredFields();
- for (Field field : fields) {
- if (!"icon".equals(field.getName()))// 除了icon之外的图片
- {
- int index = 0;
- try {
- index = field.getInt(R.drawable.class);
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- // 保存图片ID
- imgList.add(index);
- }
- }
- // 取得图像大小
- Bitmap bmImg = BitmapFactory.decodeResource(getResources(),
- imgList.get(0));
- imgWidth = bmImg.getWidth();
- imgHeight = bmImg.getHeight();