BitmapFactory.decodeStream всегда возвращает NULL - PullRequest
2 голосов
/ 07 сентября 2011

Я пытаюсь получить картинку, только что сделанную с помощью камеры со следующим кодом, но у меня всегда одна и та же ошибка:

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

(Это не исключение).Таким образом, растровое изображение объекта всегда равно NULL, и я не могу видеть, что картинка только что сделана с помощью камеры, и которую я вижу с помощью File Explorer из 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());
    }           

}

1 Ответ

0 голосов
/ 07 сентября 2011

Попробуйте следующее:


     // 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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...