sharp
sharp

Reputation: 53

How to display bitmap from internal storage?

I saved my bitmap images in my internal storage but i can't redisplay it. I've been researching for a long time but i've not find yet.

public static void saveImages(Activity activity) throws IOException
    {  
        for (int i=0; i<categories.getItems().length; i++) {        
            OutputStream os2 = activity.openFileOutput(categories.getItems()[i].getName(),
                    Context.MODE_WORLD_READABLE);
            OutputStreamWriter osw2 = new OutputStreamWriter(os2);
            Bitmap bmp = ((BitmapDrawable)categories.getItems()[i].getCategoryImage()).getBitmap(); 
            bmp.compress(Bitmap.CompressFormat.PNG, 90, os2);
            osw2.close();
        }
    }

This code works succesfully to save images. I will redisplay that images from files. Thank you

Upvotes: 3

Views: 8092

Answers (3)

Femi
Femi

Reputation: 64700

Try this code: uses openFileInput to fetch the streams you saved and then decodes them:

for (int i=0; i<categories.getItems().length; i++) {        
InputStream is = activity.openFileInput(categories.getItems()[i].getName());
Bitmap b = BitmapFactory.decodeStream(is);

// do whatever you need with b
}

Upvotes: 5

anujprashar
anujprashar

Reputation: 6335

Try this

    File f=new File(yourdir, imagename);
    Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));

Upvotes: 5

Maikel Bollemeijer
Maikel Bollemeijer

Reputation: 6575

decode bitmap, and then make a new imageView then add the bitmap to the imageView.

Upvotes: 0

Related Questions