title: Getting bitmap from external storage
body: <p>I have saved a bitmap to external storage via FileOutputStream and am trying to retrieve that file in another class so that it can be put into a imageView. Here is where I save the bitmap:</p>
  
  <pre><code>public void SaveImage(Bitmap default_b) {
  
      String root = Environment.getExternalStorageDirectory().toString();
      File myDir = new File(root + "/saved_images");
      myDir.mkdirs();
      Random generator = new Random();
      int n = 100000;
      n = generator.nextInt(n);
      String fname = "Image-" + n +".png";
      File file = new File (myDir, fname);
      Log.i("AppInfoAdapter", "" + file);
      if (file.exists()) file.delete();
      try {
          // File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
              //  + "/" + fname + ".png");
          // FileOutputStream out = mContext.getApplicationContext().openFileOutput("bitmapA", Context.MODE_WORLD_WRITEABLE);
          FileOutputStream out = new FileOutputStream(file);
          default_b.compress(Bitmap.CompressFormat.PNG, 90, out);
          out.flush();
          out.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>and I am trying to recieve it here:</p>
  
  <pre><code>  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      // Try to reuse the views
      ImageView view = (ImageView) convertView;
      // if convert view is null then create a new instance else reuse it
      if (view == null) {
          view = new ImageView(Context);
          Log.d("GridViewAdapter", "new imageView added");
      }
      try {
          FileInputStream in = Context.openFileInput("bitmapA");
          BufferedInputStream buf = new BufferedInputStream(in);
          byte[] bitMapA = new byte[buf.available()];
          buf.read(bitMapA);
          Bitmap bM = BitmapFactory.decodeByteArray(bitMapA, 0, bitMapA.length);
          view.setImageBitmap(bM);
          if (in != null) {
              in.close();
          }
          if (buf != null) {
              buf.close();
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      view.setImageResource(drawables.get(position));
      view.setScaleType(ImageView.ScaleType.CENTER_CROP);
      view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
      view.setTag(String.valueOf(position));
      return view;
  }
  </code></pre>
  
  <p>I have done plenty of searching on this and have come across multiple ways of doing the same thing but for at the moment, this way of doing it doesn't work. </p>
  
  <p>I have seen it where you use openFileOutput and openFileInput and then I have also seen where people just create new FileInput and Output streams.</p>
  
  <p>Which one is better to use for the bitmap?</p>
  
  <p>and then depending on which one is better to use (since I have both set up for when I save the bitmap), how can I get that bitmap from external storage?</p>
  
  <p>Thanks!</p>