2011-11-30 95 views
1

我有一个整型的质量,女巫我用这样的:从SD卡一样清晰度的图像读取

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

要设置点击图片:

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

此文件是在drowable。当我以同样的方式使用SD卡上的文件时,我需要做什么? 我尝试做这样的事情:

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") }; 

但它是错的,我得到一个错误:

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

回答

0

你得到一个NumberFormatException异常,因为你试图解析完全合格的路径以整数形式表示文件的名称。这是不可能的。

为了从SD卡中使用的图像,你必须把它读成位图,然后传递到图像视图:

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