Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read image from internal memory in android?

Tags:

android

this screen shot of my internal memory storage which i save image already.
i want to read image in image view. so how to get path of image or how can i read image from internal memory? please help me..

i tried some code but its not working:-

 FileInputStream fis;
        String filePath = activity.getFilesDir().getPath();
         String path = data.get(position).get("product_image");
         fis = openFileInput(filePath+"/broccolicasserole.jpg");
         Bitmap      bitmapA = BitmapFactory.decodeStream(fis);
         producticon.setImageBitmap(bitmapA);

image name is get from database like :-data.get(position).get("product_image");
also try this code also:-

  >  String filePath = activity.getFilesDir().getPath();
   File filePath1 =   imageLoader.DisplayImage(filePath+data.get(position).get("product_image"), producticon);

this is my internal memory which i save that image already

like image 471
tej shah Avatar asked Jul 01 '15 07:07

tej shah


People also ask

How do I view an image in a specific folder Android?

If you only want to search in a specific folder - use a specific Uri. File myFile = new File("/scard/myfolder"); Uri myUri = Uri. fromFile(myFile);


1 Answers

private String readFileFromInternalStorage(){
    ImageView imageView = (ImageView) findViewById(R.id.image);
    ContextWrapper cw = new ContextWrapper(context);

    //path to /data/data/yourapp/app_data/dirName
    File directory = cw.getDir("dirName", Context.MODE_PRIVATE);          
    File mypath=new File(directory,"imagename.jpg");

    ImageView imageView = (ImageView) findViewById(R.id.image);
    imageView.setImageDrawable(Drawable.createFromPath(mypath.toString()));
}

Code isn't tested. Or Try Below!

private void setImage(String imgPath)
{

    try {
        File f=new File(imgPath, "imgName.jpg");
        Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
        ImageView img=(ImageView)findViewById(R.id.image);
        img.setImageBitmap(b);
    } 
    catch (FileNotFoundException e) 
    {
        e.printStackTrace();
    }

}
like image 139
Anoop M Maddasseri Avatar answered Sep 29 '22 13:09

Anoop M Maddasseri