Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 975
sharp Avatar asked Dec 11 '25 16:12

sharp


2 Answers

Try this

    File f=new File(yourdir, imagename);
    Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
like image 120
anujprashar Avatar answered Dec 14 '25 05:12

anujprashar


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
}
like image 28
Femi Avatar answered Dec 14 '25 06:12

Femi