Displaying images and managing memory in android
<p>I wrote a program that at any time displays 8 user selected images on the screen. Each image is taken from its original form and scaled down to a uniform size. In order to do this I am using the code bellow:</p>

<pre><code>Bitmap bitmapOrg = BitmapFactory.decodeFile(File Location Here);

        int width = bitmapOrg.getWidth();
        int height = bitmapOrg.getHeight();
        int newWidth = 100;
        int newHeight = 100;

        // calculate the scale - in this case = 0.4f
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;

        // createa matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bit map
        matrix.postScale(scaleWidth, scaleHeight);

        // recreate the new Bitmap
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
                height, matrix, true);
        // make a Drawable from Bitmap to allow to set the BitMap
        // to the ImageView, ImageButton or what ever
        BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

        //ImageView imageView = new ImageView(this);
        ImageView iv = (ImageView) findViewById(R.id.imageView1);

        // set the Drawable on the ImageView
        iv.setImageDrawable(bmd);

        // center the Image
        iv.setScaleType(ScaleType.CENTER);
</code></pre>

<p>Even though my code works its not perfect. It seems like im using up a lot of memory especially calling this code possibly 8 times at once. Where in the code would i "recycle" the memory and how could i make this code possibly run better?</p>

<p>EDIT:</p>

<p>So i implemented the code in my project and it was working perfect and then i tried to add it to other sections and it just stopped working all together. my code looks like this: any idea what im doing wrong? </p>

<pre><code>    BitmapFactory.Options options = new BitmapFactory.Options(); 
 options.outWidth = 50; 
 options.outHeight = 50; Bitmap bitmap = BitmapFactory.decodeFile(path, options);
 ImageView iv = (ImageView) findViewById(R.id.imageView7); 
 iv.setImageBitmap(bitmap);
</code></pre>
