2

So I'm trying to restore an image from a file in my app's private files directory.

InputStream inputStream;
BitMapDrawable result;
    try {
        inputStream = new FileInputStream(file.getAbsolutePath());
        result = BitmapDrawable.createFromStream(inputStream, null);
        inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } 
return result;

But obviously I'm doing something wrong because result is always null.

spacitron
  • 2,095
  • 7
  • 30
  • 39
  • What did LogCat show you? Have you tried `BitmapFactory`? – CommonsWare Feb 04 '14 at 20:51
  • `e.printStackTrace();` never do this on android, instead `Log.e("someStringValue", e.getMessage(), e);` Then you will get propper logging in logcat and know what the error is. – petey Feb 04 '14 at 22:12
  • Could you close this question by accepting an answer or adding one if the existing ones didn't solve this, thanks – Nick Cardoso Apr 27 '14 at 17:32

2 Answers2

3
new BitmapDrawable( BitmapFactory.decodeFile(file.getAbsolutePath()) );
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
-1

Isn't It what you want?

Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
Drawable d = new BitmapDrawable(getResources(),bitmap);
imageview.setImageDrawable(d);
Sagar Shah
  • 4,272
  • 2
  • 25
  • 36
  • Nope, I need to use the image as the background of a layout and it won't take a bitmap, only a drawable. – spacitron Feb 04 '14 at 21:23