2014-01-19 95 views
1

在我的程序中,我必须将图像路径更改为位图。图像路径已经退出,但是当我更改为位图时,位图始终显示为空。我不知道发生了什么事。这是我的代码。位图始终显示空?

String dirName = Environment.getExternalStorageDirectory().toString()+picturePath; 
    File sddir = new File(dirName); 

     Bitmap myBitmap = BitmapFactory.decodeFile(sddir.getAbsolutePath()); 
      //Drawable d = new BitmapDrawable(getResources(), myBitmap); 
     Log.i("mybitmap",myBitmap+""); 

    Log.i("dirName",dirName+""); 
    Log.i("FileName",sddir+""); 

请给我一些建议...

编辑:logcat的输出:

01-19 11:56:18.085: I/mybitmap(1469): null 
01-19 11:56:18.085: I/dirName(1469): /mnt/sdcard/mnt/sdcard/447650.jpg 
01-19 11:56:18.085: I/FileName(1469): /mnt/sdcard/mnt/sdcard/447650.jpg 
01-19 12:19:59.754: I/PicturePath(1671): /mnt/sdcard/62afbdb0c0d287195c0eb7793427b8b8.jpg 
+0

“图像路径已经退出”是什么意思? –

+0

我的意思是图像路径退出。我知道它是因为Log.i显示图片路径。 – Halo

+0

'Environment.getExternalStorageDirectory()。toString()+ picturePath'的返回值是什么?你可以发布'dirName'字符串值... –

回答

1

你的位图路径是错误的,要附加的路径到SD卡的两倍。试试这个:

Bitmap myBitmap = BitmapFactory.decodeFile("/mnt/sdcard/447650.jpg"); 

OR

Bitmap myBitmap = BitmapFactory.decodeFile(picturePath); 

OR

picturePath相对于SD卡的路径的路径。