dwarkesh
dwarkesh

Reputation: 1388

How to read image file stored in internal memory?

In my android application I an storing an image file in internal memory using below code-

FileOutputStream fos = con.openFileOutput(fileName, con.MODE_PRIVATE);
fos.write(baf.toByteArray()); // baf - ByteArrayBuffer
fos.close();

Can any one please help me to read this image file from internal display it in an activty?

Upvotes: 7

Views: 18471

Answers (1)

Konstantin Burov
Konstantin Burov

Reputation: 69228

Try this:

ImageView imageView = (ImageView) findViewById(R.id.image);
File filePath = getFileStreamPath(fileName);
imageView.setImageDrawable(Drawable.createFromPath(filePath.toString()));

In the above snippet R.id.image is id of ImageView somewhere in your layout. fileName is a String containing name of the file you used in openFileOutput call.

Upvotes: 17

Related Questions