6

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

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
tej shah
  • 2,995
  • 2
  • 25
  • 35

2 Answers2

7
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();
    }

}
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
  • just try both code. not got image error geting like:- 07-01 03:35:54.131: W/System.err(6169): java.io.FileNotFoundException: /data/data/com.wtow.restaurant/app_imageDir/Restaurant/broccolicasserole.jpg: open failed: ENOENT (No such file or directory) 07-01 03:35:54.131: W/System.err(6169): at libcore.io.IoBridge.open(IoBridge.java:409) 07-01 03:35:54.131: W/System.err(6169): at java.io.FileInputStream.(FileInputStream.java:78) – tej shah Jul 01 '15 at 07:40
  • where you installed the app,in external memory or internal ? – Anoop M Maddasseri Jul 01 '15 at 07:47
  • Try to get the path according to the storage medium. – Anoop M Maddasseri Jul 01 '15 at 07:51
  • but now again error of out of memory.. how can i solve that – tej shah Jul 01 '15 at 08:55
  • Take a look at http://stackoverflow.com/questions/29861929/java-lang-outofmemoryerror-android/29863404#29863404 – Anoop M Maddasseri Jul 01 '15 at 08:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82073/discussion-between-tej-shah-and-anoop-m). – tej shah Jul 01 '15 at 09:53
1

Try like this it will Work ,

ImageView  picture = (ImageView) findViewById(R.id.imageView1);  

       String pic = result.getString(YourImagepathname);//get path of your image
        Bitmap yourSelectedImage1 = BitmapFactory.decodeFile(pic);
       picture.setImageBitmap(yourSelectedImage1);
Android Dev
  • 421
  • 8
  • 26
  • not image display error of log cat is :- Unable to decode stream: java.io.FileNotFoundException: /data/data/com.wtow.restaurant/app_imageDir/Restaurant/broccolicasserole.jpg: open failed: ENOENT (No such file or directory) – tej shah Jul 01 '15 at 07:44
  • so your image saved in local memory of application, Then path saved in Local Database right? – Android Dev Jul 01 '15 at 07:47
  • problem in your image Path directory saving in your database – Android Dev Jul 01 '15 at 07:50
  • /data/data/com.wtow.restaurant/app_files/Restaurant/broccolicasserole.jpg- this is your Correct path of a image. you are saving as a /data/data/com.wtow.restaurant/app_imageDir/Restaurant/broccolicasserole.jpg – Android Dev Jul 01 '15 at 07:57
  • but now again error of out of memory.. how can i solve that – tej shah Jul 01 '15 at 08:54