title: Create a file from drawable
body: <p>I have a large number of resources in my drawable folder.All are having big size more than 500KB. I have to load all these 25 images all at once in a srollView. As usual I ran out of memory. Is there any way to reduce the size of the image programmatically.</p>
  
  <p>I got this function but it's parameter is a File and I don't know how to create a File from a drawable.</p>
  
  <pre>
  
  private Bitmap decodeFile(File f){
      Bitmap b = null;
      try {
          //Decode image size
          BitmapFactory.Options o = new BitmapFactory.Options();
          o.inJustDecodeBounds = true;
  
          FileInputStream fis = new FileInputStream(f);
          BitmapFactory.decodeStream(fis, null, o);
          fis.close();
  
          int scale = 1;
          if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
              scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
          }
  
          //Decode with inSampleSize
          BitmapFactory.Options o2 = new BitmapFactory.Options();
          o2.inSampleSize = scale;
          fis = new FileInputStream(f);
          b = BitmapFactory.decodeStream(fis, null, o2);
          fis.close();
      } catch (FileNotFoundException e) {
      }
      return b;
  }
  </pre>
  
  <p>I have to go thorugh this screen cyclically many times after a number of traversal the system is showing Low memory and it is removing the other views in the back from the stack , but I actually need it.
  Please help me.</p>