【问题标题】:BitmapFactory.decodeFile() returning null when i try to get image当我尝试获取图像时,BitmapFactory.decodeFile() 返回 null
【发布时间】:2013-02-22 07:40:53
【问题描述】:
 String imageInSD = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg";         
 Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);

 if(bitmap == null){                  
     Log.v("combine image", "null");
 }else{ 
     Log.v("combine image", "not null");                  
 }

更新:使用 Environment.getExternalStorageDirectory() 感谢您提供信息

【问题讨论】:

  • 所以你成功了吗?
  • 试试:String imageInSD = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "DCIM/Soovy/2089.jpg";
  • yes got 正在工作,正如 akashasia 提到的应该使用 Environment.getExternalStorageDirectory()

标签: android bitmapfactory


【解决方案1】:

不要直接访问SD卡,尝试通过Environment访问。

像这样:

String imageDir = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg";

Bitmap bitmap = BitmapFactory.decodeFile(imageDir);

if(bitmap == null){                  
     Log.v("combine image", "null");
 }else{ 
     Log.v("combine image", "not null");                  
 }

【讨论】:

    【解决方案2】:

    试试这个:

    String imageInSD = "file:///mnt/sdcard/DCIM/Soovy/2089.jpg";        
    

    但是,您不应该对路径进行硬编码。使用

    Environment.getExternalStorageState()
    

    获取 sdcard 的根目录。

    String imageInSD = Environment.getExternalStorageState() + "/DCIM/Soovy/2089.jpg";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多