Display multiple, filtered images
<p>In my application it's possible to take pictures which are than stored in a specific directory on sd card. I would like to display them all somehow. There are though 2 problems:</p>

<ul>
<li>The photos are big (8 Mpix)</li>
<li>There can be loads of them</li>
</ul>

<p>I tried to use the default Gallery view. Unfortunately it doesn't work well with much data in it - it lags. It also throws null pointer errors - don't know why.</p>

<pre><code>        public View getView(int position, View convertView, ViewGroup parent)
        {
            if(convertView != null)
                return convertView;

            try{
                File  f = new File(mUrls[position].toString()); 
                Bitmap bmp = BitmapFactory.decodeStream(new FileInputStream(f));
                Bitmap scaledBmp = Bitmap.createScaledBitmap(bmp, 260, 210, false);
                bmp.recycle();

                convertView = new ImageView(mContext);
                ((ImageView)convertView).setScaleType(ImageView.ScaleType.FIT_XY);
                convertView.setLayoutParams(new Gallery.LayoutParams(260, 210));

//              i.setImageURI(mUrls[position]);
                ((ImageView)convertView).setImageBitmap(scaledBmp);

                return convertView;
            }catch(OutOfMemoryError e){
                return new ImageView(PhotoGalleryActivity.this);
            }catch (FileNotFoundException e){
                return new ImageView(PhotoGalleryActivity.this);
            }catch (NullPointerException e){
                return new ImageView(PhotoGalleryActivity.this); // !!! code reaches this line every time, even though it first reaches the last line of the try block
            }
        }

    }
</code></pre>

<p>When I used <strong>i.setImageURI(mUrls[position]);</strong> it caused a memory error at the start of the activity. Using scaled bitmap helped.</p>

<p>I also tried to use the default android gallery application by intent. It would be fine, but I need to filter the images by a directory. It seems impossible in default gallery app.</p>

<p>Can you help me fix one of the approaches I presented? Or maybe suggest something more suitable?</p>
