简体   繁体   English

从SD卡读取图像,例如res

[英]Reading images from sd-card like res

I have mass of int, witch I use like this: 我有大量的int,我用这样的女巫:

 final int[] iconN = new int[] { R.drawable.arrow_left_a,
   R.drawable.arrow_right_a, R.drawable.sound_on,
   R.drawable.sound_off };

To set image on click: 单击设置图像:

final ImageView bL = (ImageView) findViewById(R.id.iV1);
  bL.setOnClickListener(new OnClickListener() {
     public void onClick(View v) {
       bL.setImageResource(iconN[0]);
   }
  });

This files are in drowable. 该文件是可移动的。 What I need to do when I'll work with files from sd-card the same way? 以相同方式处理sd卡中的文件时需要做什么? I try to do something like this: 我尝试做这样的事情:

final int[] iconC = new int[] {
            Integer.parseInt(iA.getSdDir() + "/Files/Colors/arrow_left_a.png"),
            Integer.parseInt(iA.getSdDir() + "/Files/Colors/arrow_right_a.png") };

But it's wrong and I get an err: 但这是错误的,我得到了一个错误:

 java.lang.NumberFormatException: unable to parse '/mnt/sdcard/izuchaika//Files/Colors/arrow_left_a.png' as integer

You're getting a numberFormatException because you're trying to parse the fully-qualified path name for a file as an integer. 之所以得到numberFormatException,是因为您试图将文件的标准路径名解析为整数。 That won't be possible. 那是不可能的。

To use the image from the SD card, you have to read it into a bitmap and then pass that to the image view: 要使用SD卡中的图像,您必须将其读入位图,然后将其传递到图像视图:

bl.setImageBitmap(BitmapFactory.decodeFile(iA.getSdDir()+"/Files/Colors/arrow_left_a.png"));

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

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