BitmapFactory.decodeStream总是返回NULL

问题描述:

我试图得到一个PIC只用后面的代码凸轮做到了,但我一直同样的错误:BitmapFactory.decodeStream总是返回NULL

skia(446): --- SkImageDecoder::Factory returned null 

(它不会抛出例外)。因此,对象位图始终为NULL,我无法看到使用凸轮创建的图片,而我可以使用Eclipse的文件浏览器查看该图片。

发生了什么事?我怎样才能解决这个问题?

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.view_photo);   
    ImageView imagen = (ImageView)findViewById(R.id.foto); 
    try { 
     Cursor cur = this.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, null, null, null,null); 
     String str = cur.getString(cur.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME)); 
     cur.moveToLast(); 

     FileInputStream in = new FileInputStream("/sdcard/DCIM/Camera/" + str); 
     BufferedInputStream buf = new BufferedInputStream(in, 24); 
     Bitmap bMap = BitmapFactory.decodeStream(buf); 
     if (bMap != null) 
      imagen.setImageBitmap(bMap); 
     else{ 
      Log.d("onCreate: ", "bMap es NULL"); 
     } 
     if (in != null) { 
      in.close(); 
      Log.d("onCreate: ", "in cerrado"); 
     } 
     if (buf != null) { 
      buf.close(); 
      Log.d("onCreate: ", "buf cerrado"); 
     } 
     Log.d("onCreate: ", "Fin del proceso"); 
    }catch (Exception e) { 
     Log.e("Error reading file", e.toString()); 
    }   

} 

尝试以下操作:


    // get the SD Card path, you need to check first if this is available 
    File sdcard = Environment.getExternalStorageDirectory(); 

    // I am assuming str is your filename, make sure you are getting the right value for this one 
    File file = new File(sdcard.getAbsolutePath(), str); 

    // Note that the buffer size is in bytes, so 24 in your question is very low 
    BufferedInputStream buf = new BufferedInputStream(in, 8192); 
    Bitmap bMap = BitmapFactory.decodeStream(buf);