How to display bitmap from internal storage?

泄露秘密 提交于 2019-12-12 02:31:31

问题


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


回答1:


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
}



回答2:


Try this

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



回答3:


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



来源:https://stackoverflow.com/questions/7593737/how-to-display-bitmap-from-internal-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!